]> granicus.if.org Git - python/commitdiff
Fix various spots where int/long and str/unicode unification
authorWalter Dörwald <walter@livinglogic.de>
Thu, 3 May 2007 21:05:51 +0000 (21:05 +0000)
committerWalter Dörwald <walter@livinglogic.de>
Thu, 3 May 2007 21:05:51 +0000 (21:05 +0000)
lead to type checks like isinstance(foo, (str, str)) or
isinstance(foo, (int, int)).

14 files changed:
Lib/ctypes/__init__.py
Lib/ctypes/test/test_as_parameter.py
Lib/ctypes/test/test_functions.py
Lib/decimal.py
Lib/doctest.py
Lib/msilib/__init__.py
Lib/plat-mac/EasyDialogs.py
Lib/plat-mac/plistlib.py
Lib/random.py
Lib/subprocess.py
Lib/test/test_array.py
Lib/test/test_long.py
Lib/test/test_struct.py
Lib/test/test_unicode.py

index 76090178591e8872f36c186ff8abea03086aec14..b753a6b899fe36a322337a17b66fe0296607c7c7 100644 (file)
@@ -59,14 +59,14 @@ def create_string_buffer(init, size=None):
     create_string_buffer(anInteger) -> character array
     create_string_buffer(aString, anInteger) -> character array
     """
-    if isinstance(init, (str, str)):
+    if isinstance(init, str):
         if size is None:
             size = len(init)+1
         buftype = c_char * size
         buf = buftype()
         buf.value = init
         return buf
-    elif isinstance(init, (int, int)):
+    elif isinstance(init, int):
         buftype = c_char * init
         buf = buftype()
         return buf
@@ -281,14 +281,14 @@ else:
         create_unicode_buffer(anInteger) -> character array
         create_unicode_buffer(aString, anInteger) -> character array
         """
-        if isinstance(init, (str, str)):
+        if isinstance(init, str):
             if size is None:
                 size = len(init)+1
             buftype = c_wchar * size
             buf = buftype()
             buf.value = init
             return buf
-        elif isinstance(init, (int, int)):
+        elif isinstance(init, int):
             buftype = c_wchar * init
             buf = buftype()
             return buf
@@ -359,7 +359,7 @@ class CDLL(object):
 
     def __getitem__(self, name_or_ordinal):
         func = self._FuncPtr((name_or_ordinal, self))
-        if not isinstance(name_or_ordinal, (int, int)):
+        if not isinstance(name_or_ordinal, int):
             func.__name__ = name_or_ordinal
         return func
 
index e21782b2462c8c1cf0694f1efd81d627f16f1b9a..884361c548f0ad481ec1de7b344c6344d7a56def 100644 (file)
@@ -133,7 +133,7 @@ class BasicWrapTestCase(unittest.TestCase):
         f.argtypes = [c_longlong, MyCallback]
 
         def callback(value):
-            self.failUnless(isinstance(value, (int, int)))
+            self.failUnless(isinstance(value, int))
             return value & 0x7FFFFFFF
 
         cb = MyCallback(callback)
index bbcbbc1b0da7f6c412235f78d897d5562ad2a289..9e5a6f8c88c6677e52bb6ffe09b2eaf0de8d8006 100644 (file)
@@ -293,7 +293,7 @@ class FunctionTestCase(unittest.TestCase):
         f.argtypes = [c_longlong, MyCallback]
 
         def callback(value):
-            self.failUnless(isinstance(value, (int, int)))
+            self.failUnless(isinstance(value, int))
             return value & 0x7FFFFFFF
 
         cb = MyCallback(callback)
index a7238e19ea24f684ff1394b5f77d6612eb898af1..2611f79789ff1f94c4a45cbd60ef249dc1abcb0a 100644 (file)
@@ -741,32 +741,32 @@ class Decimal(object):
         return 1
 
     def __eq__(self, other):
-        if not isinstance(other, (Decimal, int, int)):
+        if not isinstance(other, (Decimal, int)):
             return NotImplemented
         return self.__cmp__(other) == 0
 
     def __ne__(self, other):
-        if not isinstance(other, (Decimal, int, int)):
+        if not isinstance(other, (Decimal, int)):
             return NotImplemented
         return self.__cmp__(other) != 0
 
     def __lt__(self, other):
-        if not isinstance(other, (Decimal, int, int)):
+        if not isinstance(other, (Decimal, int)):
             return NotImplemented
         return self.__cmp__(other) < 0
 
     def __le__(self, other):
-        if not isinstance(other, (Decimal, int, int)):
+        if not isinstance(other, (Decimal, int)):
             return NotImplemented
         return self.__cmp__(other) <= 0
 
     def __gt__(self, other):
-        if not isinstance(other, (Decimal, int, int)):
+        if not isinstance(other, (Decimal, int)):
             return NotImplemented
         return self.__cmp__(other) > 0
 
     def __ge__(self, other):
-        if not isinstance(other, (Decimal, int, int)):
+        if not isinstance(other, (Decimal, int)):
             return NotImplemented
         return self.__cmp__(other) >= 0
 
@@ -2993,7 +2993,7 @@ def _convert_other(other):
     """
     if isinstance(other, Decimal):
         return other
-    if isinstance(other, (int, int)):
+    if isinstance(other, int):
         return Decimal(other)
     return NotImplemented
 
index d237811dade902e9faa5357a598d45f050d220f4..cb29fcb7824d0b5e78b3bd5d02e4e1bbbf7af1bf 100644 (file)
@@ -196,7 +196,7 @@ def _normalize_module(module, depth=2):
     """
     if inspect.ismodule(module):
         return module
-    elif isinstance(module, (str, str)):
+    elif isinstance(module, str):
         return __import__(module, globals(), locals(), ["*"])
     elif module is None:
         return sys.modules[sys._getframe(depth).f_globals['__name__']]
index 27b03ea24abbcf27193891a7d6c04a30a82f6140..ad3bf623a519cefe7d23b629ca897113757f6a00 100644 (file)
@@ -99,7 +99,7 @@ def add_data(db, table, values):
         assert len(value) == count, value
         for i in range(count):
             field = value[i]
-            if isinstance(field, (int, int)):
+            if isinstance(field, int):
                 r.SetInteger(i+1,field)
             elif isinstance(field, basestring):
                 r.SetString(i+1,field)
index 6d157f90a2d53275c43e29e527ff6f2c21f92103..dfed24f13abf6e9f76192ac153e038a060f1b5a7 100644 (file)
@@ -713,7 +713,7 @@ def AskFileForSave(
         raise TypeError, "Cannot pass wanted=FSRef to AskFileForSave"
     if issubclass(tpwanted, Carbon.File.FSSpec):
         return tpwanted(rr.selection[0])
-    if issubclass(tpwanted, (str, str)):
+    if issubclass(tpwanted, str):
         if sys.platform == 'mac':
             fullpath = rr.selection[0].as_pathname()
         else:
index b04023739ebe3f7ddc3f04c33130fb6c9a09d433..049b50bdc5bc64ba5a09f7f22acac45f3d4a301a 100644 (file)
@@ -70,7 +70,7 @@ def readPlist(pathOrFile):
     usually is a dictionary).
     """
     didOpen = 0
-    if isinstance(pathOrFile, (str, str)):
+    if isinstance(pathOrFile, str):
         pathOrFile = open(pathOrFile)
         didOpen = 1
     p = PlistParser()
@@ -85,7 +85,7 @@ def writePlist(rootObject, pathOrFile):
     file name or a (writable) file object.
     """
     didOpen = 0
-    if isinstance(pathOrFile, (str, str)):
+    if isinstance(pathOrFile, str):
         pathOrFile = open(pathOrFile, "w")
         didOpen = 1
     writer = PlistWriter(pathOrFile)
@@ -231,7 +231,7 @@ class PlistWriter(DumbXMLWriter):
         DumbXMLWriter.__init__(self, file, indentLevel, indent)
 
     def writeValue(self, value):
-        if isinstance(value, (str, str)):
+        if isinstance(value, str):
             self.simpleElement("string", value)
         elif isinstance(value, bool):
             # must switch for bool before int, as bool is a
@@ -270,7 +270,7 @@ class PlistWriter(DumbXMLWriter):
         self.beginElement("dict")
         items = sorted(d.items())
         for key, value in items:
-            if not isinstance(key, (str, str)):
+            if not isinstance(key, str):
                 raise TypeError("keys must be strings")
             self.simpleElement("key", key)
             self.writeValue(value)
index 8adcff5f6dd508ca63226d65b150e250b5e9a03a..99ae75027176553224b412da1d6ebb2cbb997d36 100644 (file)
@@ -631,7 +631,7 @@ class WichmannHill(Random):
                 import time
                 a = int(time.time() * 256) # use fractional seconds
 
-        if not isinstance(a, (int, int)):
+        if not isinstance(a, int):
             a = hash(a)
 
         a, x = divmod(a, 30268)
index 2aa02ae4f53be093602b4e12c6ac8199531df11c..363c827f9f046618004c0b43060f90f364b8c64f 100644 (file)
@@ -541,7 +541,7 @@ class Popen(object):
         _cleanup()
 
         self._child_created = False
-        if not isinstance(bufsize, (int, int)):
+        if not isinstance(bufsize, int):
             raise TypeError("bufsize must be an integer")
 
         if mswindows:
index b84557015f4f5f5b6583cae83aef71d971bb7b78..5278f2329dd8d798749c12f5bc60777e21adb401 100755 (executable)
@@ -65,7 +65,7 @@ class BaseTest(unittest.TestCase):
         bi = a.buffer_info()
         self.assert_(isinstance(bi, tuple))
         self.assertEqual(len(bi), 2)
-        self.assert_(isinstance(bi[0], (int, int)))
+        self.assert_(isinstance(bi[0], int))
         self.assert_(isinstance(bi[1], int))
         self.assertEqual(bi[1], len(a))
 
index 2876f83b6b3fc589c0790340577970afeaf58d2b..1f652029a9b84fafdabc7b0fc5cbcc102bc6c5cd 100644 (file)
@@ -426,7 +426,7 @@ class LongTest(unittest.TestCase):
         # represents all Python ints, longs and floats exactly).
         class Rat:
             def __init__(self, value):
-                if isinstance(value, (int, int)):
+                if isinstance(value, int):
                     self.n = value
                     self.d = 1
                 elif isinstance(value, float):
index b62d74cd94888fb5b701bc4fdb40c8d8a82ca1ba..c3df2226d344d79b79f7254cac36bb6be5c9b556 100644 (file)
@@ -492,12 +492,11 @@ test_705836()
 def test_1229380():
     import sys
     for endian in ('', '>', '<'):
-        for cls in (int, int):
-            for fmt in ('B', 'H', 'I', 'L'):
-                deprecated_err(struct.pack, endian + fmt, cls(-1))
+        for fmt in ('B', 'H', 'I', 'L'):
+            deprecated_err(struct.pack, endian + fmt, -1)
 
-            deprecated_err(struct.pack, endian + 'B', cls(300))
-            deprecated_err(struct.pack, endian + 'H', cls(70000))
+        deprecated_err(struct.pack, endian + 'B', 300)
+        deprecated_err(struct.pack, endian + 'H', 70000)
 
         deprecated_err(struct.pack, endian + 'I', sys.maxint * 4)
         deprecated_err(struct.pack, endian + 'L', sys.maxint * 4)
index 3dd92aec507ea5e0818a4e6b702cde6a297ad48b..ccfa92207e3317336499a02ef444a904b3b14ac1 100644 (file)
@@ -134,31 +134,27 @@ class UnicodeTest(
 
     def test_index(self):
         string_tests.CommonTest.test_index(self)
-        # check mixed argument types
-        for (t1, t2) in ((str, str), (str, str)):
-            self.checkequalnofix(0, t1('abcdefghiabc'), 'index',  t2(''))
-            self.checkequalnofix(3, t1('abcdefghiabc'), 'index',  t2('def'))
-            self.checkequalnofix(0, t1('abcdefghiabc'), 'index',  t2('abc'))
-            self.checkequalnofix(9, t1('abcdefghiabc'), 'index',  t2('abc'), 1)
-            self.assertRaises(ValueError, t1('abcdefghiabc').index, t2('hib'))
-            self.assertRaises(ValueError, t1('abcdefghiab').index,  t2('abc'), 1)
-            self.assertRaises(ValueError, t1('abcdefghi').index,  t2('ghi'), 8)
-            self.assertRaises(ValueError, t1('abcdefghi').index,  t2('ghi'), -1)
+        self.checkequalnofix(0, 'abcdefghiabc', 'index',  '')
+        self.checkequalnofix(3, 'abcdefghiabc', 'index',  'def')
+        self.checkequalnofix(0, 'abcdefghiabc', 'index',  'abc')
+        self.checkequalnofix(9, 'abcdefghiabc', 'index',  'abc', 1)
+        self.assertRaises(ValueError, 'abcdefghiabc'.index, 'hib')
+        self.assertRaises(ValueError, 'abcdefghiab'.index,  'abc', 1)
+        self.assertRaises(ValueError, 'abcdefghi'.index,  'ghi', 8)
+        self.assertRaises(ValueError, 'abcdefghi'.index,  'ghi', -1)
 
     def test_rindex(self):
         string_tests.CommonTest.test_rindex(self)
-        # check mixed argument types
-        for (t1, t2) in ((str, str), (str, str)):
-            self.checkequalnofix(12, t1('abcdefghiabc'), 'rindex',  t2(''))
-            self.checkequalnofix(3,  t1('abcdefghiabc'), 'rindex',  t2('def'))
-            self.checkequalnofix(9,  t1('abcdefghiabc'), 'rindex',  t2('abc'))
-            self.checkequalnofix(0,  t1('abcdefghiabc'), 'rindex',  t2('abc'), 0, -1)
-
-            self.assertRaises(ValueError, t1('abcdefghiabc').rindex,  t2('hib'))
-            self.assertRaises(ValueError, t1('defghiabc').rindex,  t2('def'), 1)
-            self.assertRaises(ValueError, t1('defghiabc').rindex,  t2('abc'), 0, -1)
-            self.assertRaises(ValueError, t1('abcdefghi').rindex,  t2('ghi'), 0, 8)
-            self.assertRaises(ValueError, t1('abcdefghi').rindex,  t2('ghi'), 0, -1)
+        self.checkequalnofix(12, 'abcdefghiabc', 'rindex',  '')
+        self.checkequalnofix(3,  'abcdefghiabc', 'rindex',  'def')
+        self.checkequalnofix(9,  'abcdefghiabc', 'rindex',  'abc')
+        self.checkequalnofix(0,  'abcdefghiabc', 'rindex',  'abc', 0, -1)
+
+        self.assertRaises(ValueError, 'abcdefghiabc'.rindex,  'hib')
+        self.assertRaises(ValueError, 'defghiabc'.rindex,  'def', 1)
+        self.assertRaises(ValueError, 'defghiabc'.rindex,  'abc', 0, -1)
+        self.assertRaises(ValueError, 'abcdefghi'.rindex,  'ghi', 0, 8)
+        self.assertRaises(ValueError, 'abcdefghi'.rindex,  'ghi', 0, -1)
 
     def test_translate(self):
         self.checkequalnofix('bbbc', 'abababc', 'translate', {ord('a'):None})