Skip to content

Commit 09781e2

Browse files
committed
修复了扩展类型List的一些bug,同时优化了__repr__()方法
1 parent 2b3565d commit 09781e2

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

type.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
对Python原版类型的扩展
33
"""
44
__author__ = "Jerry"
5-
__version__ = "1.3.7"
5+
__version__ = "1.3.8"
66

77
__all__ = ["String", "Integer", "List"]
88

@@ -269,7 +269,19 @@ def __init__(self, list_) -> None:
269269
self.length = len(list_) # 列表长度
270270

271271
def __repr__(self) -> str:
272-
return "[%s]"%(", ".join(self.__list))
272+
r = []
273+
for i in self.__list:
274+
if type(i) is str:
275+
r.append("'%s'"%i)
276+
elif type(i) is int:
277+
r.append(str(i))
278+
elif type(i) is String:
279+
r.append("<Extension Type String '%s'>"%i.getNormal())
280+
elif type(i) is Integer:
281+
r.append("<Extension Type Integer %s>"%i.toStr())
282+
elif type(i) is List:
283+
r.append("<Extension Type List %s>"%i.getNormal())
284+
return "[%s]"%(", ".join(r))
273285

274286
__str__ = __repr__
275287

@@ -341,7 +353,7 @@ def toStrList(self):
341353
"如果列表包含整数,返回一个将整数转为字符串的列表"
342354
strList = []
343355
for i in self.__list:
344-
if i is int:
356+
if type(i) is int:
345357
strList.append(str(i))
346358
else:
347359
strList.append(i)
@@ -351,8 +363,9 @@ def toIntList(self):
351363
"如果列表包含字符串,返回一个将字符串转为整数的列表"
352364
intList = []
353365
for i in self.__list:
354-
if i.isdigit():
355-
intList.append(int(i))
366+
if type(i) is str:
367+
if i.isdigit():
368+
intList.append(int(i))
356369
else:
357370
intList.append(i)
358371
return intList
@@ -361,7 +374,7 @@ def toStringList(self):
361374
"如果列表包含字符串,返回一个将字符串转为String对象的列表"
362375
stringList = []
363376
for i in self.__list:
364-
if i is str:
377+
if type(i) is str:
365378
stringList.append(String(i))
366379
else:
367380
stringList.append(i)
@@ -371,7 +384,7 @@ def toIntegerList(self):
371384
"如果列表包含整数,返回一个将整数转为Integer对象的列表"
372385
integerList = []
373386
for i in self.__list:
374-
if i is int:
387+
if type(i) is int:
375388
integerList.append(Integer(i))
376389
else:
377390
integerList.append(i)

0 commit comments

Comments
 (0)