Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit aa97f04

Browse files
committed
Fix various spots where int/long and str/unicode unification
lead to type checks like isinstance(foo, (str, str)) or isinstance(foo, (int, int)).
1 parent 5d7a700 commit aa97f04

14 files changed

Lines changed: 47 additions & 52 deletions

Lib/ctypes/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ def create_string_buffer(init, size=None):
5959
create_string_buffer(anInteger) -> character array
6060
create_string_buffer(aString, anInteger) -> character array
6161
"""
62-
if isinstance(init, (str, str)):
62+
if isinstance(init, str):
6363
if size is None:
6464
size = len(init)+1
6565
buftype = c_char * size
6666
buf = buftype()
6767
buf.value = init
6868
return buf
69-
elif isinstance(init, (int, int)):
69+
elif isinstance(init, int):
7070
buftype = c_char * init
7171
buf = buftype()
7272
return buf
@@ -281,14 +281,14 @@ def create_unicode_buffer(init, size=None):
281281
create_unicode_buffer(anInteger) -> character array
282282
create_unicode_buffer(aString, anInteger) -> character array
283283
"""
284-
if isinstance(init, (str, str)):
284+
if isinstance(init, str):
285285
if size is None:
286286
size = len(init)+1
287287
buftype = c_wchar * size
288288
buf = buftype()
289289
buf.value = init
290290
return buf
291-
elif isinstance(init, (int, int)):
291+
elif isinstance(init, int):
292292
buftype = c_wchar * init
293293
buf = buftype()
294294
return buf
@@ -359,7 +359,7 @@ def __getattr__(self, name):
359359

360360
def __getitem__(self, name_or_ordinal):
361361
func = self._FuncPtr((name_or_ordinal, self))
362-
if not isinstance(name_or_ordinal, (int, int)):
362+
if not isinstance(name_or_ordinal, int):
363363
func.__name__ = name_or_ordinal
364364
return func
365365

Lib/ctypes/test/test_as_parameter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def test_longlong_callbacks(self):
133133
f.argtypes = [c_longlong, MyCallback]
134134

135135
def callback(value):
136-
self.failUnless(isinstance(value, (int, int)))
136+
self.failUnless(isinstance(value, int))
137137
return value & 0x7FFFFFFF
138138

139139
cb = MyCallback(callback)

Lib/ctypes/test/test_functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ def test_longlong_callbacks(self):
293293
f.argtypes = [c_longlong, MyCallback]
294294

295295
def callback(value):
296-
self.failUnless(isinstance(value, (int, int)))
296+
self.failUnless(isinstance(value, int))
297297
return value & 0x7FFFFFFF
298298

299299
cb = MyCallback(callback)

Lib/decimal.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -741,32 +741,32 @@ def __cmp__(self, other, context=None):
741741
return 1
742742

743743
def __eq__(self, other):
744-
if not isinstance(other, (Decimal, int, int)):
744+
if not isinstance(other, (Decimal, int)):
745745
return NotImplemented
746746
return self.__cmp__(other) == 0
747747

748748
def __ne__(self, other):
749-
if not isinstance(other, (Decimal, int, int)):
749+
if not isinstance(other, (Decimal, int)):
750750
return NotImplemented
751751
return self.__cmp__(other) != 0
752752

753753
def __lt__(self, other):
754-
if not isinstance(other, (Decimal, int, int)):
754+
if not isinstance(other, (Decimal, int)):
755755
return NotImplemented
756756
return self.__cmp__(other) < 0
757757

758758
def __le__(self, other):
759-
if not isinstance(other, (Decimal, int, int)):
759+
if not isinstance(other, (Decimal, int)):
760760
return NotImplemented
761761
return self.__cmp__(other) <= 0
762762

763763
def __gt__(self, other):
764-
if not isinstance(other, (Decimal, int, int)):
764+
if not isinstance(other, (Decimal, int)):
765765
return NotImplemented
766766
return self.__cmp__(other) > 0
767767

768768
def __ge__(self, other):
769-
if not isinstance(other, (Decimal, int, int)):
769+
if not isinstance(other, (Decimal, int)):
770770
return NotImplemented
771771
return self.__cmp__(other) >= 0
772772

@@ -2993,7 +2993,7 @@ def _convert_other(other):
29932993
"""
29942994
if isinstance(other, Decimal):
29952995
return other
2996-
if isinstance(other, (int, int)):
2996+
if isinstance(other, int):
29972997
return Decimal(other)
29982998
return NotImplemented
29992999

Lib/doctest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def _normalize_module(module, depth=2):
196196
"""
197197
if inspect.ismodule(module):
198198
return module
199-
elif isinstance(module, (str, str)):
199+
elif isinstance(module, str):
200200
return __import__(module, globals(), locals(), ["*"])
201201
elif module is None:
202202
return sys.modules[sys._getframe(depth).f_globals['__name__']]

Lib/msilib/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def add_data(db, table, values):
9999
assert len(value) == count, value
100100
for i in range(count):
101101
field = value[i]
102-
if isinstance(field, (int, int)):
102+
if isinstance(field, int):
103103
r.SetInteger(i+1,field)
104104
elif isinstance(field, basestring):
105105
r.SetString(i+1,field)

Lib/plat-mac/EasyDialogs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ def AskFileForSave(
713713
raise TypeError, "Cannot pass wanted=FSRef to AskFileForSave"
714714
if issubclass(tpwanted, Carbon.File.FSSpec):
715715
return tpwanted(rr.selection[0])
716-
if issubclass(tpwanted, (str, str)):
716+
if issubclass(tpwanted, str):
717717
if sys.platform == 'mac':
718718
fullpath = rr.selection[0].as_pathname()
719719
else:

Lib/plat-mac/plistlib.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def readPlist(pathOrFile):
7070
usually is a dictionary).
7171
"""
7272
didOpen = 0
73-
if isinstance(pathOrFile, (str, str)):
73+
if isinstance(pathOrFile, str):
7474
pathOrFile = open(pathOrFile)
7575
didOpen = 1
7676
p = PlistParser()
@@ -85,7 +85,7 @@ def writePlist(rootObject, pathOrFile):
8585
file name or a (writable) file object.
8686
"""
8787
didOpen = 0
88-
if isinstance(pathOrFile, (str, str)):
88+
if isinstance(pathOrFile, str):
8989
pathOrFile = open(pathOrFile, "w")
9090
didOpen = 1
9191
writer = PlistWriter(pathOrFile)
@@ -231,7 +231,7 @@ def __init__(self, file, indentLevel=0, indent="\t", writeHeader=1):
231231
DumbXMLWriter.__init__(self, file, indentLevel, indent)
232232

233233
def writeValue(self, value):
234-
if isinstance(value, (str, str)):
234+
if isinstance(value, str):
235235
self.simpleElement("string", value)
236236
elif isinstance(value, bool):
237237
# must switch for bool before int, as bool is a
@@ -270,7 +270,7 @@ def writeDict(self, d):
270270
self.beginElement("dict")
271271
items = sorted(d.items())
272272
for key, value in items:
273-
if not isinstance(key, (str, str)):
273+
if not isinstance(key, str):
274274
raise TypeError("keys must be strings")
275275
self.simpleElement("key", key)
276276
self.writeValue(value)

Lib/random.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ def seed(self, a=None):
631631
import time
632632
a = int(time.time() * 256) # use fractional seconds
633633

634-
if not isinstance(a, (int, int)):
634+
if not isinstance(a, int):
635635
a = hash(a)
636636

637637
a, x = divmod(a, 30268)

Lib/subprocess.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ def __init__(self, args, bufsize=0, executable=None,
541541
_cleanup()
542542

543543
self._child_created = False
544-
if not isinstance(bufsize, (int, int)):
544+
if not isinstance(bufsize, int):
545545
raise TypeError("bufsize must be an integer")
546546

547547
if mswindows:

0 commit comments

Comments
 (0)