1. Bitbucket Website
  2. Public Issue Tracker
  3. pyflakes3k-brodie

Commits

Brodie Rao  committed 7fb0279

Made minor modifications to support both Python 2 and 3 simultaneously

  • Participants
  • Parent commits 97bea1b
  • Branches default

Comments (0)

Files changed (5)

File pyflakes/checker.py

View file
 # (c) 2005-2010 Divmod, Inc.
 # See LICENSE file for details
 
-import builtins
-import os.path
+try:
+    import builtins
+except ImportError:
+    import __builtin__ as builtins
+
 import _ast
+import os
+import sys
 
 from pyflakes import messages
 
     def handleNode(self, node, parent):
         node.parent = parent
         if self.traceTree:
-            print('  ' * self.nodeDepth + node.__class__.__name__)
+            sys.stdout.write('  ' * self.nodeDepth + node.__class__.__name__ +
+                             '\n')
         self.nodeDepth += 1
         if self.futuresAllowed and not \
                (isinstance(node, _ast.ImportFrom) or self.isDocstring(node)):
         finally:
             self.nodeDepth -= 1
         if self.traceTree:
-            print('  ' * self.nodeDepth + 'end ' + node.__class__.__name__)
+            sys.stdout.write('  ' * self.nodeDepth + 'end ' +
+                             node.__class__.__name__ + '\n')
 
     def ignore(self, node):
         pass
                     if isinstance(arg, _ast.Tuple):
                         addArgs(arg.elts)
                     else:
-                        if arg.arg in args:
+                        try:
+                            id_ = arg.arg
+                        except AttributeError:
+                            id_ = arg.id
+                        if id_ in args:
                             self.report(messages.DuplicateArgument,
-                                        node.lineno, arg.arg)
-                        args.append(arg.arg)
+                                        node.lineno, id_)
+                        args.append(id_)
 
             self.pushFunctionScope()
             addArgs(node.args.args)

File pyflakes/scripts/pyflakes.py

View file
             # Avoid using msg, since for the only known case, it contains a
             # bogus message that claims the encoding the file declared was
             # unknown.
-            print("%s: problem decoding source" % (filename, ), file=sys.stderr)
+            sys.stderr.write('%s: problem decoding source\n' % filename)
         else:
             line = text.splitlines()[-1]
 
             if offset is not None:
                 offset = offset - (len(text) - len(line))
 
-            print('%s:%d: %s' % (filename, lineno, msg), file=sys.stderr)
-            print(line, file=sys.stderr)
+            sys.stderr.write('%s:%d: %s\n' % (filename, lineno, msg))
+            sys.stderr.write(line + '\n')
 
             if offset is not None:
-                print(" " * offset, "^", file=sys.stderr)
+                sys.stderr.write(' ' * offset + ' ^\n')
 
         return 1
     else:
         w = checker.Checker(tree, filename)
         w.messages.sort(key=lambda m: m.lineno)
         for warning in w.messages:
-            print(warning)
+            sys.stdout.write(warning + '\n')
         return len(w.messages)
 
 
     try:
         return check(open(filename, 'rb').read() + b'\n', filename)
     except IOError as msg:
-        print("%s: %s" % (filename, msg.args[1]), file=sys.stderr)
+        sys.stderr.write('%s: %s\n' % (filename, msg.args[1]))
         return 1
 
 

File pyflakes/test/test_imports.py

View file
         self.flakes('from moo import fu as FU, bar as FU', m.RedefinedWhileUnused, m.UnusedImport)
 
     def test_usedImport(self):
-        self.flakes('import fu; print(fu)')
-        self.flakes('from baz import fu; print(fu)')
+        self.flakes('import fu; min(fu)')
+        self.flakes('from baz import fu; min(fu)')
 
     def test_redefinedWhileUnused(self):
         self.flakes('import fu; fu = 3', m.RedefinedWhileUnused)
         import fu
         class bar:
             fu = 1
-        print(fu)
+        min(fu)
         ''')
 
     def test_usedInFunction(self):
         self.flakes('''
         import fu
         def fun():
-            print(fu)
+            min(fu)
         ''')
 
     def test_shadowedByParameter(self):
         self.flakes('''
         import fu
         def fun(fu):
-            print(fu)
+            min(fu)
         ''', m.UnusedImport)
 
         self.flakes('''
         import fu
         def fun(fu):
-            print(fu)
-        print(fu)
+            min(fu)
+        min(fu)
         ''')
 
     def test_newAssignment(self):
         self.flakes('import fu; "bar".fu.baz', m.UnusedImport)
 
     def test_usedInSlice(self):
-        self.flakes('import fu; print(fu.bar[1:])')
+        self.flakes('import fu; min(fu.bar[1:])')
 
     def test_usedInIfBody(self):
         self.flakes('''
         import fu
-        if True: print(fu)
+        if True: min(fu)
         ''')
 
     def test_usedInIfConditional(self):
         self.flakes('''
         import fu
         if False: pass
-        else: print(fu)
+        else: min(fu)
         ''')
 
     def test_usedInCall(self):
         import fu
         def bleh():
             pass
-        print(fu)
+        min(fu)
         ''')
 
     def test_usedInFor(self):
         self.flakes('''
         import fu
         for bar in range(9):
-            print(fu)
+            min(fu)
         ''')
 
     def test_usedInForElse(self):
         for bar in range(10):
             pass
         else:
-            print(fu)
+            min(fu)
         ''')
 
     def test_redefinedByFor(self):
         ''', m.UnusedImport)
 
     def test_usedInExec(self):
-        self.flakes('import fu; exec("print(1)" in fu.bar)')
+        self.flakes('import fu; exec("min(1)" in fu.bar)')
 
     def test_usedInLambda(self):
         self.flakes('import fu; lambda: fu')
             import fu
             class b:
                 def c(self):
-                    print(fu)
+                    min(fu)
         ''')
 
     def test_importStar(self):

File pyflakes/test/test_script.py

View file
 Tests for L{pyflakes.scripts.pyflakes}.
 """
 
+try:
+    from cStringIO import StringIO
+except ImportError:
+    from io import StringIO
+
+import os
 import sys
-from io import StringIO
 import tempfile
-import os.path
-import os
-
 from unittest import TestCase
 
 from pyflakes.scripts.pyflakes import checkPath
         If a source file contains bytes which cannot be decoded, this is
         reported on stderr.
         """
-        source = """\
+        try:
+            unicode
+        except NameError:
+            source = """\
 # coding: ascii
 x = "\N{SNOWMAN}"
 """.encode('utf-8')
+        else:
+            source = """\
+# coding: ascii
+x = "\xe2\x98\x83"
+"""
         sourcePath = fileWithContents(source)
         err = StringIO()
         count = withStderrTo(err, lambda: checkPath(sourcePath))

File pyflakes/test/test_undefined_names.py

View file
         self.flakes('''
         global x
         def foo():
-            print(x)
+            min(x)
         ''', m.UndefinedName)
 
     def test_del(self):
                 def h(self):
                     a = x
                     x = None
-                    print(x, a)
-            print(x)
+                    min(x, a)
+            min(x)
         ''', m.UndefinedLocal)
 
 
         '''star and double-star arg names are defined'''
         self.flakes('''
         def f(a, *b, **c):
-            print(a, b, c)
+            min(a, b, c)
         ''')
 
     def test_definedInGenExp(self):