[Python-checkins] r77310 - in python/trunk: Lib/binhex.py Lib/bsddb/__init__.py Lib/compiler/ast.py Lib/compiler/pycodegen.py Lib/dbhash.py Lib/formatter.py Lib/imputil.py Lib/lib2to3/pgen2/tokenize.py Lib/mailbox.py Lib/pprint.py Lib/pstats.py Lib/sets.py Lib/sunau.py Lib/unittest/case.py Lib/wave.py Lib/webbrowser.py Misc/NEWS Tools/compiler/astgen.py

antoine.pitrou python-checkins at python.org
Tue Jan 5 00:22:44 CET 2010


Author: antoine.pitrou
Date: Tue Jan  5 00:22:44 2010
New Revision: 77310

Log:
Issue #7092: Fix the DeprecationWarnings emitted by the standard library
when using the -3 flag.  Patch by Florent Xicluna.



Modified:
   python/trunk/Lib/binhex.py
   python/trunk/Lib/bsddb/__init__.py
   python/trunk/Lib/compiler/ast.py
   python/trunk/Lib/compiler/pycodegen.py
   python/trunk/Lib/dbhash.py
   python/trunk/Lib/formatter.py
   python/trunk/Lib/imputil.py
   python/trunk/Lib/lib2to3/pgen2/tokenize.py
   python/trunk/Lib/mailbox.py
   python/trunk/Lib/pprint.py
   python/trunk/Lib/pstats.py
   python/trunk/Lib/sets.py
   python/trunk/Lib/sunau.py
   python/trunk/Lib/unittest/case.py
   python/trunk/Lib/wave.py
   python/trunk/Lib/webbrowser.py
   python/trunk/Misc/NEWS
   python/trunk/Tools/compiler/astgen.py

Modified: python/trunk/Lib/binhex.py
==============================================================================
--- python/trunk/Lib/binhex.py	(original)
+++ python/trunk/Lib/binhex.py	Tue Jan  5 00:22:44 2010
@@ -170,7 +170,8 @@
         del self.ofp
 
 class BinHex:
-    def __init__(self, (name, finfo, dlen, rlen), ofp):
+    def __init__(self, name_finfo_dlen_rlen, ofp):
+        name, finfo, dlen, rlen = name_finfo_dlen_rlen
         if type(ofp) == type(''):
             ofname = ofp
             ofp = open(ofname, 'w')

Modified: python/trunk/Lib/bsddb/__init__.py
==============================================================================
--- python/trunk/Lib/bsddb/__init__.py	(original)
+++ python/trunk/Lib/bsddb/__init__.py	Tue Jan  5 00:22:44 2010
@@ -44,7 +44,7 @@
 
 if sys.py3kwarning:
     import warnings
-    warnings.warnpy3k("in 3.x, bsddb has been removed; "
+    warnings.warnpy3k("in 3.x, the bsddb module has been removed; "
                       "please use the pybsddb project instead",
                       DeprecationWarning, 2)
 

Modified: python/trunk/Lib/compiler/ast.py
==============================================================================
--- python/trunk/Lib/compiler/ast.py	(original)
+++ python/trunk/Lib/compiler/ast.py	Tue Jan  5 00:22:44 2010
@@ -51,9 +51,9 @@
         return "Expression(%s)" % (repr(self.node))
 
 class Add(Node):
-    def __init__(self, (left, right), lineno=None):
-        self.left = left
-        self.right = right
+    def __init__(self, leftright, lineno=None):
+        self.left = leftright[0]
+        self.right = leftright[1]
         self.lineno = lineno
 
     def getChildren(self):
@@ -431,9 +431,9 @@
         return "Discard(%s)" % (repr(self.expr),)
 
 class Div(Node):
-    def __init__(self, (left, right), lineno=None):
-        self.left = left
-        self.right = right
+    def __init__(self, leftright, lineno=None):
+        self.left = leftright[0]
+        self.right = leftright[1]
         self.lineno = lineno
 
     def getChildren(self):
@@ -485,9 +485,9 @@
         return "Exec(%s, %s, %s)" % (repr(self.expr), repr(self.locals), repr(self.globals))
 
 class FloorDiv(Node):
-    def __init__(self, (left, right), lineno=None):
-        self.left = left
-        self.right = right
+    def __init__(self, leftright, lineno=None):
+        self.left = leftright[0]
+        self.right = leftright[1]
         self.lineno = lineno
 
     def getChildren(self):
@@ -560,7 +560,6 @@
             self.kwargs = 1
 
 
-
     def getChildren(self):
         children = []
         children.append(self.decorators)
@@ -590,6 +589,7 @@
         self.argnames = ['.0']
         self.varargs = self.kwargs = None
 
+
     def getChildren(self):
         return self.code,
 
@@ -607,7 +607,6 @@
         self.lineno = lineno
         self.is_outmost = False
 
-
     def getChildren(self):
         children = []
         children.append(self.assign)
@@ -784,7 +783,6 @@
             self.kwargs = 1
 
 
-
     def getChildren(self):
         children = []
         children.append(self.argnames)
@@ -803,9 +801,9 @@
         return "Lambda(%s, %s, %s, %s)" % (repr(self.argnames), repr(self.defaults), repr(self.flags), repr(self.code))
 
 class LeftShift(Node):
-    def __init__(self, (left, right), lineno=None):
-        self.left = left
-        self.right = right
+    def __init__(self, leftright, lineno=None):
+        self.left = leftright[0]
+        self.right = leftright[1]
         self.lineno = lineno
 
     def getChildren(self):
@@ -893,9 +891,9 @@
         return "ListCompIf(%s)" % (repr(self.test),)
 
 class Mod(Node):
-    def __init__(self, (left, right), lineno=None):
-        self.left = left
-        self.right = right
+    def __init__(self, leftright, lineno=None):
+        self.left = leftright[0]
+        self.right = leftright[1]
         self.lineno = lineno
 
     def getChildren(self):
@@ -923,9 +921,9 @@
         return "Module(%s, %s)" % (repr(self.doc), repr(self.node))
 
 class Mul(Node):
-    def __init__(self, (left, right), lineno=None):
-        self.left = left
-        self.right = right
+    def __init__(self, leftright, lineno=None):
+        self.left = leftright[0]
+        self.right = leftright[1]
         self.lineno = lineno
 
     def getChildren(self):
@@ -995,9 +993,9 @@
         return "Pass()"
 
 class Power(Node):
-    def __init__(self, (left, right), lineno=None):
-        self.left = left
-        self.right = right
+    def __init__(self, leftright, lineno=None):
+        self.left = leftright[0]
+        self.right = leftright[1]
         self.lineno = lineno
 
     def getChildren(self):
@@ -1095,9 +1093,9 @@
         return "Return(%s)" % (repr(self.value),)
 
 class RightShift(Node):
-    def __init__(self, (left, right), lineno=None):
-        self.left = left
-        self.right = right
+    def __init__(self, leftright, lineno=None):
+        self.left = leftright[0]
+        self.right = leftright[1]
         self.lineno = lineno
 
     def getChildren(self):
@@ -1170,9 +1168,9 @@
         return "Stmt(%s)" % (repr(self.nodes),)
 
 class Sub(Node):
-    def __init__(self, (left, right), lineno=None):
-        self.left = left
-        self.right = right
+    def __init__(self, leftright, lineno=None):
+        self.left = leftright[0]
+        self.right = leftright[1]
         self.lineno = lineno
 
     def getChildren(self):

Modified: python/trunk/Lib/compiler/pycodegen.py
==============================================================================
--- python/trunk/Lib/compiler/pycodegen.py	(original)
+++ python/trunk/Lib/compiler/pycodegen.py	Tue Jan  5 00:22:44 2010
@@ -870,10 +870,10 @@
         level = node.level
         if level == 0 and not self.graph.checkFlag(CO_FUTURE_ABSIMPORT):
             level = -1
-        fromlist = map(lambda (name, alias): name, node.names)
+        fromlist = tuple(name for (name, alias) in node.names)
         if VERSION > 1:
             self.emit('LOAD_CONST', level)
-            self.emit('LOAD_CONST', tuple(fromlist))
+            self.emit('LOAD_CONST', fromlist)
         self.emit('IMPORT_NAME', node.modname)
         for name, alias in node.names:
             if VERSION > 1:

Modified: python/trunk/Lib/dbhash.py
==============================================================================
--- python/trunk/Lib/dbhash.py	(original)
+++ python/trunk/Lib/dbhash.py	Tue Jan  5 00:22:44 2010
@@ -3,7 +3,7 @@
 import sys
 if sys.py3kwarning:
     import warnings
-    warnings.warnpy3k("in 3.x, dbhash has been removed", DeprecationWarning, 2)
+    warnings.warnpy3k("in 3.x, the dbhash module has been removed", DeprecationWarning, 2)
 try:
     import bsddb
 except ImportError:

Modified: python/trunk/Lib/formatter.py
==============================================================================
--- python/trunk/Lib/formatter.py	(original)
+++ python/trunk/Lib/formatter.py	Tue Jan  5 00:22:44 2010
@@ -228,7 +228,8 @@
             self.align = None
             self.writer.new_alignment(None)
 
-    def push_font(self, (size, i, b, tt)):
+    def push_font(self, font):
+        size, i, b, tt = font
         if self.softspace:
             self.hard_break = self.para_end = self.softspace = 0
             self.nospace = 1

Modified: python/trunk/Lib/imputil.py
==============================================================================
--- python/trunk/Lib/imputil.py	(original)
+++ python/trunk/Lib/imputil.py	Tue Jan  5 00:22:44 2010
@@ -281,7 +281,8 @@
             setattr(parent, modname, module)
         return module
 
-    def _process_result(self, (ispkg, code, values), fqname):
+    def _process_result(self, result, fqname):
+        ispkg, code, values = result
         # did get_code() return an actual module? (rather than a code object)
         is_module = isinstance(code, _ModuleType)
 

Modified: python/trunk/Lib/lib2to3/pgen2/tokenize.py
==============================================================================
--- python/trunk/Lib/lib2to3/pgen2/tokenize.py	(original)
+++ python/trunk/Lib/lib2to3/pgen2/tokenize.py	Tue Jan  5 00:22:44 2010
@@ -144,7 +144,9 @@
 
 class StopTokenizing(Exception): pass
 
-def printtoken(type, token, (srow, scol), (erow, ecol), line): # for testing
+def printtoken(type, token, start, end, line): # for testing
+    (srow, scol) = start
+    (erow, ecol) = end
     print "%d,%d-%d,%d:\t%s\t%s" % \
         (srow, scol, erow, ecol, tok_name[type], repr(token))
 

Modified: python/trunk/Lib/mailbox.py
==============================================================================
--- python/trunk/Lib/mailbox.py	(original)
+++ python/trunk/Lib/mailbox.py	Tue Jan  5 00:22:44 2010
@@ -18,7 +18,6 @@
 import email
 import email.message
 import email.generator
-import rfc822
 import StringIO
 try:
     if sys.platform == 'os2emx':
@@ -28,6 +27,13 @@
 except ImportError:
     fcntl = None
 
+import warnings
+with warnings.catch_warnings():
+    if sys.py3kwarning:
+        warnings.filterwarnings("ignore", ".*rfc822 has been removed",
+                                DeprecationWarning)
+    import rfc822
+
 __all__ = [ 'Mailbox', 'Maildir', 'mbox', 'MH', 'Babyl', 'MMDF',
             'Message', 'MaildirMessage', 'mboxMessage', 'MHMessage',
             'BabylMessage', 'MMDFMessage', 'UnixMailbox',

Modified: python/trunk/Lib/pprint.py
==============================================================================
--- python/trunk/Lib/pprint.py	(original)
+++ python/trunk/Lib/pprint.py	Tue Jan  5 00:22:44 2010
@@ -35,6 +35,7 @@
 """
 
 import sys as _sys
+import warnings
 
 from cStringIO import StringIO as _StringIO
 
@@ -70,6 +71,13 @@
     """Determine if object requires a recursive representation."""
     return _safe_repr(object, {}, None, 0)[2]
 
+def _sorted(iterable):
+    with warnings.catch_warnings():
+        if _sys.py3kwarning:
+            warnings.filterwarnings("ignore", "comparing unequal types "
+                                    "not supported", DeprecationWarning)
+        return sorted(iterable)
+
 class PrettyPrinter:
     def __init__(self, indent=1, width=80, depth=None, stream=None):
         """Handle pretty printing operations onto a stream using a set of
@@ -144,8 +152,7 @@
             if length:
                 context[objid] = 1
                 indent = indent + self._indent_per_level
-                items  = object.items()
-                items.sort()
+                items = _sorted(object.items())
                 key, ent = items[0]
                 rep = self._repr(key, context, level)
                 write(rep)
@@ -181,7 +188,7 @@
                     return
                 write('set([')
                 endchar = '])'
-                object = sorted(object)
+                object = _sorted(object)
                 indent += 4
             elif issubclass(typ, frozenset):
                 if not length:
@@ -189,7 +196,7 @@
                     return
                 write('frozenset([')
                 endchar = '])'
-                object = sorted(object)
+                object = _sorted(object)
                 indent += 10
             else:
                 write('(')
@@ -274,7 +281,7 @@
         append = components.append
         level += 1
         saferepr = _safe_repr
-        for k, v in sorted(object.items()):
+        for k, v in _sorted(object.items()):
             krepr, kreadable, krecur = saferepr(k, context, maxlevels, level)
             vrepr, vreadable, vrecur = saferepr(v, context, maxlevels, level)
             append("%s: %s" % (krepr, vrepr))

Modified: python/trunk/Lib/pstats.py
==============================================================================
--- python/trunk/Lib/pstats.py	(original)
+++ python/trunk/Lib/pstats.py	Tue Jan  5 00:22:44 2010
@@ -442,12 +442,12 @@
         if nc == 0:
             print >> self.stream, ' '*8,
         else:
-            print >> self.stream, f8(tt/nc),
+            print >> self.stream, f8(float(tt)/nc),
         print >> self.stream, f8(ct),
         if cc == 0:
             print >> self.stream, ' '*8,
         else:
-            print >> self.stream, f8(ct/cc),
+            print >> self.stream, f8(float(ct)/cc),
         print >> self.stream, func_std_string(func)
 
 class TupleComp:

Modified: python/trunk/Lib/sets.py
==============================================================================
--- python/trunk/Lib/sets.py	(original)
+++ python/trunk/Lib/sets.py	Tue Jan  5 00:22:44 2010
@@ -54,29 +54,7 @@
 # - Raymond Hettinger added a number of speedups and other
 #   improvements.
 
-from __future__ import generators
-try:
-    from itertools import ifilter, ifilterfalse
-except ImportError:
-    # Code to make the module run under Py2.2
-    def ifilter(predicate, iterable):
-        if predicate is None:
-            def predicate(x):
-                return x
-        for x in iterable:
-            if predicate(x):
-                yield x
-    def ifilterfalse(predicate, iterable):
-        if predicate is None:
-            def predicate(x):
-                return x
-        for x in iterable:
-            if not predicate(x):
-                yield x
-    try:
-        True, False
-    except NameError:
-        True, False = (0==0, 0!=0)
+from itertools import ifilter, ifilterfalse
 
 __all__ = ['BaseSet', 'Set', 'ImmutableSet']
 
@@ -235,7 +213,7 @@
             little, big = self, other
         else:
             little, big = other, self
-        common = ifilter(big._data.has_key, little)
+        common = ifilter(big._data.__contains__, little)
         return self.__class__(common)
 
     def __xor__(self, other):
@@ -260,9 +238,9 @@
             otherdata = other._data
         except AttributeError:
             otherdata = Set(other)._data
-        for elt in ifilterfalse(otherdata.has_key, selfdata):
+        for elt in ifilterfalse(otherdata.__contains__, selfdata):
             data[elt] = value
-        for elt in ifilterfalse(selfdata.has_key, otherdata):
+        for elt in ifilterfalse(selfdata.__contains__, otherdata):
             data[elt] = value
         return result
 
@@ -287,7 +265,7 @@
         except AttributeError:
             otherdata = Set(other)._data
         value = True
-        for elt in ifilterfalse(otherdata.has_key, self):
+        for elt in ifilterfalse(otherdata.__contains__, self):
             data[elt] = value
         return result
 
@@ -313,7 +291,7 @@
         self._binary_sanity_check(other)
         if len(self) > len(other):  # Fast check for obvious cases
             return False
-        for elt in ifilterfalse(other._data.has_key, self):
+        for elt in ifilterfalse(other._data.__contains__, self):
             return False
         return True
 
@@ -322,7 +300,7 @@
         self._binary_sanity_check(other)
         if len(self) < len(other):  # Fast check for obvious cases
             return False
-        for elt in ifilterfalse(self._data.has_key, other):
+        for elt in ifilterfalse(self._data.__contains__, other):
             return False
         return True
 
@@ -338,6 +316,9 @@
         self._binary_sanity_check(other)
         return len(self) > len(other) and self.issuperset(other)
 
+    # We inherit object.__hash__, so we must deny this explicitly
+    __hash__ = None
+
     # Assorted helpers
 
     def _binary_sanity_check(self, other):
@@ -439,9 +420,6 @@
     def __setstate__(self, data):
         self._data, = data
 
-    # We inherit object.__hash__, so we must deny this explicitly
-    __hash__ = None
-
     # In-place union, intersection, differences.
     # Subtle:  The xyz_update() functions deliberately return None,
     # as do all mutating operations on built-in container types.
@@ -503,7 +481,7 @@
             other = Set(other)
         if self is other:
             self.clear()
-        for elt in ifilter(data.has_key, other):
+        for elt in ifilter(data.__contains__, other):
             del data[elt]
 
     # Python dict-like mass mutations: update, clear

Modified: python/trunk/Lib/sunau.py
==============================================================================
--- python/trunk/Lib/sunau.py	(original)
+++ python/trunk/Lib/sunau.py	Tue Jan  5 00:22:44 2010
@@ -364,7 +364,8 @@
         else:
             return 'not compressed'
 
-    def setparams(self, (nchannels, sampwidth, framerate, nframes, comptype, compname)):
+    def setparams(self, params):
+        nchannels, sampwidth, framerate, nframes, comptype, compname = params
         self.setnchannels(nchannels)
         self.setsampwidth(sampwidth)
         self.setframerate(framerate)

Modified: python/trunk/Lib/unittest/case.py
==============================================================================
--- python/trunk/Lib/unittest/case.py	(original)
+++ python/trunk/Lib/unittest/case.py	Tue Jan  5 00:22:44 2010
@@ -746,9 +746,15 @@
             # not hashable.
             expected = list(expected_seq)
             actual = list(actual_seq)
-            expected.sort()
-            actual.sort()
-            missing, unexpected = util.sorted_list_difference(expected, actual)
+            with warnings.catch_warnings():
+                if sys.py3kwarning:
+                    # Silence Py3k warning
+                    warnings.filterwarnings("ignore",
+                                            "dict inequality comparisons "
+                                            "not supported", DeprecationWarning)
+                expected.sort()
+                actual.sort()
+                missing, unexpected = util.sorted_list_difference(expected, actual)
         errors = []
         if missing:
             errors.append('Expected, but missing:\n    %r' % missing)

Modified: python/trunk/Lib/wave.py
==============================================================================
--- python/trunk/Lib/wave.py	(original)
+++ python/trunk/Lib/wave.py	Tue Jan  5 00:22:44 2010
@@ -384,7 +384,8 @@
     def getcompname(self):
         return self._compname
 
-    def setparams(self, (nchannels, sampwidth, framerate, nframes, comptype, compname)):
+    def setparams(self, params):
+        nchannels, sampwidth, framerate, nframes, comptype, compname = params
         if self._datawritten:
             raise Error, 'cannot change parameters after starting to write'
         self.setnchannels(nchannels)

Modified: python/trunk/Lib/webbrowser.py
==============================================================================
--- python/trunk/Lib/webbrowser.py	(original)
+++ python/trunk/Lib/webbrowser.py	Tue Jan  5 00:22:44 2010
@@ -650,7 +650,7 @@
     for o, a in opts:
         if o == '-n': new_win = 1
         elif o == '-t': new_win = 2
-    if len(args) <> 1:
+    if len(args) != 1:
         print >>sys.stderr, usage
         sys.exit(1)
 

Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Tue Jan  5 00:22:44 2010
@@ -65,6 +65,9 @@
 Library
 -------
 
+- Issue #7092: Fix the DeprecationWarnings emitted by the standard library
+  when using the -3 flag.  Patch by Florent Xicluna.
+
 - Issue #7471: Improve the performance of GzipFile's buffering mechanism,
   and make it implement the `io.BufferedIOBase` ABC to allow for further
   speedups by wrapping it in an `io.BufferedReader`.  Patch by Nir Aides.

Modified: python/trunk/Tools/compiler/astgen.py
==============================================================================
--- python/trunk/Tools/compiler/astgen.py	(original)
+++ python/trunk/Tools/compiler/astgen.py	Tue Jan  5 00:22:44 2010
@@ -105,12 +105,18 @@
 
     def _gen_init(self, buf):
         if self.args:
-            print >> buf, "    def __init__(self, %s, lineno=None):" % self.args
+            argtuple = '(' in self.args
+            args = self.args if not argtuple else ''.join(self.argnames)
+            print >> buf, "    def __init__(self, %s, lineno=None):" % args
         else:
             print >> buf, "    def __init__(self, lineno=None):"
         if self.argnames:
-            for name in self.argnames:
-                print >> buf, "        self.%s = %s" % (name, name)
+            if argtuple:
+                for idx, name in enumerate(self.argnames):
+                    print >> buf, "        self.%s = %s[%s]" % (name, args, idx)
+            else:
+                for name in self.argnames:
+                    print >> buf, "        self.%s = %s" % (name, name)
         print >> buf, "        self.lineno = lineno"
         # Copy the lines in self.init, indented four spaces.  The rstrip()
         # business is to get rid of the four spaces if line happens to be


More information about the Python-checkins mailing list