[Python-checkins] r55105 - in python/branches/py3k-struni/Lib: ctypes/__init__.py ctypes/test/test_as_parameter.py ctypes/test/test_functions.py decimal.py doctest.py msilib/__init__.py plat-mac/EasyDialogs.py plat-mac/plistlib.py random.py subprocess.py test/test_array.py test/test_long.py test/test_struct.py test/test_unicode.py

walter.doerwald python-checkins at python.org
Thu May 3 23:05:56 CEST 2007


Author: walter.doerwald
Date: Thu May  3 23:05:51 2007
New Revision: 55105

Modified:
   python/branches/py3k-struni/Lib/ctypes/__init__.py
   python/branches/py3k-struni/Lib/ctypes/test/test_as_parameter.py
   python/branches/py3k-struni/Lib/ctypes/test/test_functions.py
   python/branches/py3k-struni/Lib/decimal.py
   python/branches/py3k-struni/Lib/doctest.py
   python/branches/py3k-struni/Lib/msilib/__init__.py
   python/branches/py3k-struni/Lib/plat-mac/EasyDialogs.py
   python/branches/py3k-struni/Lib/plat-mac/plistlib.py
   python/branches/py3k-struni/Lib/random.py
   python/branches/py3k-struni/Lib/subprocess.py
   python/branches/py3k-struni/Lib/test/test_array.py
   python/branches/py3k-struni/Lib/test/test_long.py
   python/branches/py3k-struni/Lib/test/test_struct.py
   python/branches/py3k-struni/Lib/test/test_unicode.py
Log:
Fix various spots where int/long and str/unicode unification
lead to type checks like isinstance(foo, (str, str)) or
isinstance(foo, (int, int)).


Modified: python/branches/py3k-struni/Lib/ctypes/__init__.py
==============================================================================
--- python/branches/py3k-struni/Lib/ctypes/__init__.py	(original)
+++ python/branches/py3k-struni/Lib/ctypes/__init__.py	Thu May  3 23:05:51 2007
@@ -59,14 +59,14 @@
     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 @@
         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 @@
 
     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
 

Modified: python/branches/py3k-struni/Lib/ctypes/test/test_as_parameter.py
==============================================================================
--- python/branches/py3k-struni/Lib/ctypes/test/test_as_parameter.py	(original)
+++ python/branches/py3k-struni/Lib/ctypes/test/test_as_parameter.py	Thu May  3 23:05:51 2007
@@ -133,7 +133,7 @@
         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)

Modified: python/branches/py3k-struni/Lib/ctypes/test/test_functions.py
==============================================================================
--- python/branches/py3k-struni/Lib/ctypes/test/test_functions.py	(original)
+++ python/branches/py3k-struni/Lib/ctypes/test/test_functions.py	Thu May  3 23:05:51 2007
@@ -293,7 +293,7 @@
         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)

Modified: python/branches/py3k-struni/Lib/decimal.py
==============================================================================
--- python/branches/py3k-struni/Lib/decimal.py	(original)
+++ python/branches/py3k-struni/Lib/decimal.py	Thu May  3 23:05:51 2007
@@ -741,32 +741,32 @@
         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 @@
     """
     if isinstance(other, Decimal):
         return other
-    if isinstance(other, (int, int)):
+    if isinstance(other, int):
         return Decimal(other)
     return NotImplemented
 

Modified: python/branches/py3k-struni/Lib/doctest.py
==============================================================================
--- python/branches/py3k-struni/Lib/doctest.py	(original)
+++ python/branches/py3k-struni/Lib/doctest.py	Thu May  3 23:05:51 2007
@@ -196,7 +196,7 @@
     """
     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__']]

Modified: python/branches/py3k-struni/Lib/msilib/__init__.py
==============================================================================
--- python/branches/py3k-struni/Lib/msilib/__init__.py	(original)
+++ python/branches/py3k-struni/Lib/msilib/__init__.py	Thu May  3 23:05:51 2007
@@ -99,7 +99,7 @@
         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)

Modified: python/branches/py3k-struni/Lib/plat-mac/EasyDialogs.py
==============================================================================
--- python/branches/py3k-struni/Lib/plat-mac/EasyDialogs.py	(original)
+++ python/branches/py3k-struni/Lib/plat-mac/EasyDialogs.py	Thu May  3 23:05:51 2007
@@ -713,7 +713,7 @@
         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:

Modified: python/branches/py3k-struni/Lib/plat-mac/plistlib.py
==============================================================================
--- python/branches/py3k-struni/Lib/plat-mac/plistlib.py	(original)
+++ python/branches/py3k-struni/Lib/plat-mac/plistlib.py	Thu May  3 23:05:51 2007
@@ -70,7 +70,7 @@
     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 @@
     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 @@
         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 @@
         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)

Modified: python/branches/py3k-struni/Lib/random.py
==============================================================================
--- python/branches/py3k-struni/Lib/random.py	(original)
+++ python/branches/py3k-struni/Lib/random.py	Thu May  3 23:05:51 2007
@@ -631,7 +631,7 @@
                 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)

Modified: python/branches/py3k-struni/Lib/subprocess.py
==============================================================================
--- python/branches/py3k-struni/Lib/subprocess.py	(original)
+++ python/branches/py3k-struni/Lib/subprocess.py	Thu May  3 23:05:51 2007
@@ -541,7 +541,7 @@
         _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:

Modified: python/branches/py3k-struni/Lib/test/test_array.py
==============================================================================
--- python/branches/py3k-struni/Lib/test/test_array.py	(original)
+++ python/branches/py3k-struni/Lib/test/test_array.py	Thu May  3 23:05:51 2007
@@ -65,7 +65,7 @@
         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))
 

Modified: python/branches/py3k-struni/Lib/test/test_long.py
==============================================================================
--- python/branches/py3k-struni/Lib/test/test_long.py	(original)
+++ python/branches/py3k-struni/Lib/test/test_long.py	Thu May  3 23:05:51 2007
@@ -426,7 +426,7 @@
         # 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):

Modified: python/branches/py3k-struni/Lib/test/test_struct.py
==============================================================================
--- python/branches/py3k-struni/Lib/test/test_struct.py	(original)
+++ python/branches/py3k-struni/Lib/test/test_struct.py	Thu May  3 23:05:51 2007
@@ -492,12 +492,11 @@
 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)

Modified: python/branches/py3k-struni/Lib/test/test_unicode.py
==============================================================================
--- python/branches/py3k-struni/Lib/test/test_unicode.py	(original)
+++ python/branches/py3k-struni/Lib/test/test_unicode.py	Thu May  3 23:05:51 2007
@@ -134,31 +134,27 @@
 
     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})


More information about the Python-checkins mailing list