[Python-checkins] commit of r41538 - python/trunk/Lib/compiler

neal.norwitz@python.org neal.norwitz at python.org
Fri Nov 25 04:18:04 CET 2005


Author: neal.norwitz
Date: Fri Nov 25 04:17:59 2005
New Revision: 41538

Modified:
   python/trunk/Lib/compiler/misc.py
   python/trunk/Lib/compiler/pyassem.py
   python/trunk/Lib/compiler/pycodegen.py
Log:
No need for types, use isinstance

Modified: python/trunk/Lib/compiler/misc.py
==============================================================================
--- python/trunk/Lib/compiler/misc.py	(original)
+++ python/trunk/Lib/compiler/misc.py	Fri Nov 25 04:17:59 2005
@@ -1,9 +1,8 @@
-import types
 
 def flatten(tup):
     elts = []
     for elt in tup:
-        if type(elt) == types.TupleType:
+        if isinstance(elt, tuple):
             elts = elts + flatten(elt)
         else:
             elts.append(elt)

Modified: python/trunk/Lib/compiler/pyassem.py
==============================================================================
--- python/trunk/Lib/compiler/pyassem.py	(original)
+++ python/trunk/Lib/compiler/pyassem.py	Fri Nov 25 04:17:59 2005
@@ -3,7 +3,6 @@
 import dis
 import new
 import sys
-import types
 
 from compiler import misc
 from compiler.consts \
@@ -641,7 +640,7 @@
 
 def twobyte(val):
     """Convert an int argument into high and low bytes"""
-    assert type(val) == types.IntType
+    assert isinstance(val, int)
     return divmod(val, 256)
 
 class LineAddrTable:

Modified: python/trunk/Lib/compiler/pycodegen.py
==============================================================================
--- python/trunk/Lib/compiler/pycodegen.py	(original)
+++ python/trunk/Lib/compiler/pycodegen.py	Fri Nov 25 04:17:59 2005
@@ -3,7 +3,6 @@
 import marshal
 import struct
 import sys
-import types
 from cStringIO import StringIO
 
 from compiler import ast, parse, walk, syntax
@@ -1312,7 +1311,7 @@
     def generateArgUnpack(self, args):
         for i in range(len(args)):
             arg = args[i]
-            if type(arg) == types.TupleType:
+            if isinstance(arg, tuple):
                 self.emit('LOAD_FAST', '.%d' % (i * 2))
                 self.unpackSequence(arg)
 
@@ -1322,7 +1321,7 @@
         else:
             self.emit('UNPACK_TUPLE', len(tup))
         for elt in tup:
-            if type(elt) == types.TupleType:
+            if isinstance(elt, tuple):
                 self.unpackSequence(elt)
             else:
                 self._nameOp('STORE', elt)
@@ -1408,9 +1407,9 @@
     count = 0
     for i in range(len(arglist)):
         elt = arglist[i]
-        if type(elt) == types.StringType:
+        if isinstance(elt, str):
             args.append(elt)
-        elif type(elt) == types.TupleType:
+        elif isinstance(elt, tuple):
             args.append(TupleArg(i * 2, elt))
             extra.extend(misc.flatten(elt))
             count = count + 1


More information about the Python-checkins mailing list