UtilitiesPython2/py2flakes/checker.py

Tue, 29 Apr 2014 23:28:07 +0200

author
T.Rzepka <Tobias.Rzepka@gmail.com>
date
Tue, 29 Apr 2014 23:28:07 +0200
branch
5_4_x
changeset 3551
d608f3f42d71
parent 3160
209a07d7e401
permissions
-rw-r--r--

updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)

802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
3160
209a07d7e401 Updated copyright for 2014.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2998
diff changeset
3 # Copyright (c) 2011 - 2014 Detlev Offenbach <detlev@die-offenbachs.de>
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
1535
f2650ea19bb8 Migrated py2flakes to v0.5.0 in order to fix issues for Python 2.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
5 # Original (c) 2005-2010 Divmod, Inc.
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 #
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 # This module is based on pyflakes for Python2 but was heavily hacked to
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 # work within eric5
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
10 """
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
11 Main module.
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
12
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
13 Implement the central Checker class.
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
14 Also, it models the Bindings and Scopes.
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
15 """
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
16 import doctest
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
17 import os
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
18 import sys
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
19
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
20 PY2 = sys.version_info < (3, 0)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
21 PY32 = sys.version_info < (3, 3) # Python 2.5 to 3.2
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
22 PY33 = sys.version_info < (3, 4) # Python 2.5 to 3.3
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
23 builtin_vars = dir(__import__('__builtin__' if PY2 else 'builtins'))
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
24
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
25 try:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
26 import ast
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
27 except ImportError: # Python 2.5
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
28 import _ast as ast
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
29
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
30 if 'decorator_list' not in ast.ClassDef._fields:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
31 # Patch the missing attribute 'decorator_list'
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
32 ast.ClassDef.decorator_list = ()
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
33 ast.FunctionDef.decorator_list = property(lambda s: s.decorators)
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 from py2flakes import messages
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 802
diff changeset
37
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
38 if PY2:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
39 def getNodeType(node_class):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
40 # workaround str.upper() which is locale-dependent
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
41 return str(unicode(node_class.__name__).upper()) # __IGNORE_WARNING__
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
42 else:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
43 def getNodeType(node_class):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
44 return node_class.__name__.upper()
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
45
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
46 # Python >= 3.3 uses ast.Try instead of (ast.TryExcept + ast.TryFinally)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
47 if PY32:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
48 def getAlternatives(n):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
49 if isinstance(n, (ast.If, ast.TryFinally)):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
50 return [n.body]
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
51 if isinstance(n, ast.TryExcept):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
52 return [n.body + n.orelse] + [[hdl] for hdl in n.handlers]
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
53 else:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
54 def getAlternatives(n):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
55 if isinstance(n, ast.If):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
56 return [n.body]
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
57 if isinstance(n, ast.Try):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
58 return [n.body + n.orelse] + [[hdl] for hdl in n.handlers]
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
59
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
60
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
61 class _FieldsOrder(dict):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
62 """Fix order of AST node fields."""
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
63
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
64 def _get_fields(self, node_class):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
65 # handle iter before target, and generators before element
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
66 fields = node_class._fields
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
67 if 'iter' in fields:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
68 key_first = 'iter'.find
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
69 elif 'generators' in fields:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
70 key_first = 'generators'.find
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
71 else:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
72 key_first = 'value'.find
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
73 return tuple(sorted(fields, key=key_first, reverse=True))
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
74
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
75 def __missing__(self, node_class):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
76 self[node_class] = fields = self._get_fields(node_class)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
77 return fields
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
78
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
79
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
80 def iter_child_nodes(node, omit=None, _fields_order=_FieldsOrder()):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
81 """
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
82 Yield all direct child nodes of *node*, that is, all fields that
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
83 are nodes and all items of fields that are lists of nodes.
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
84 """
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
85 for name in _fields_order[node.__class__]:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
86 if name == omit:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
87 continue
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
88 field = getattr(node, name, None)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
89 if isinstance(field, ast.AST):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
90 yield field
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
91 elif isinstance(field, list):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
92 for item in field:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
93 yield item
1535
f2650ea19bb8 Migrated py2flakes to v0.5.0 in order to fix issues for Python 2.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
94
f2650ea19bb8 Migrated py2flakes to v0.5.0 in order to fix issues for Python 2.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
95
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 class Binding(object):
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 """
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 Represents the binding of a value to a name.
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 The checker uses this to keep track of which names have been bound and
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 which names have not. See L{Assignment} for a special type of binding that
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 is checked with stricter rules.
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
103
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
104 @ivar used: pair of (L{Scope}, line-number) indicating the scope and
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
105 line number that this binding was last used
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 """
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
107
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 def __init__(self, name, source):
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 self.name = name
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 self.source = source
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 self.used = False
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113 def __str__(self):
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 return self.name
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 def __repr__(self):
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
117 return '<%s object %r from line %r at 0x%x>' % (self.__class__.__name__,
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
118 self.name,
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
119 self.source.lineno,
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
120 id(self))
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
121
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
122 def redefines(self, other):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
123 return isinstance(other, Definition) and self.name == other.name
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
124
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
125
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
126 class Definition(Binding):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
127 """
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
128 A binding that defines a function or a class.
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
129 """
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 802
diff changeset
131
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
132 class Importation(Definition):
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133 """
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134 A binding created by an import statement.
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
135
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
136 @ivar fullName: The complete name given to the import statement,
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
137 possibly including multiple dotted components.
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
138 @type fullName: C{str}
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139 """
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
140
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141 def __init__(self, name, source):
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
142 self.fullName = name
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
143 self.redefined = []
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144 name = name.split('.')[0]
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145 super(Importation, self).__init__(name, source)
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
147 def redefines(self, other):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
148 if isinstance(other, Importation):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
149 return self.fullName == other.fullName
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
150 return isinstance(other, Definition) and self.name == other.name
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
151
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 802
diff changeset
152
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153 class Argument(Binding):
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154 """
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155 Represents binding a name as an argument.
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156 """
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 802
diff changeset
158
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
159 class Assignment(Binding):
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 """
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161 Represents binding a name with an explicit assignment.
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163 The checker will raise warnings for any Assignment that isn't used. Also,
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
164 the checker does not consider assignments in tuple/list unpacking to be
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165 Assignments, rather it treats them as simple Bindings.
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166 """
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 802
diff changeset
168
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
169 class FunctionDefinition(Definition):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
170 pass
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
171
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
172
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
173 class ClassDefinition(Definition):
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
174 pass
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
175
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 802
diff changeset
176
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
177 class ExportBinding(Binding):
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
178 """
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
179 A binding created by an C{__all__} assignment. If the names in the list
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
180 can be determined statically, they will be treated as names for export and
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
181 additional checking applied to them.
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
182
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
183 The only C{__all__} assignment that can be recognized is one which takes
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
184 the value of a literal list containing literal strings. For example::
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
185
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
186 __all__ = ["foo", "bar"]
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
188 Names which are imported and not otherwise used but appear in the value of
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
189 C{__all__} will not have an unused import warning reported for them.
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
190 """
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
191
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
192 def __init__(self, name, source, scope):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
193 if '__all__' in scope and isinstance(source, ast.AugAssign):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
194 self.names = list(scope['__all__'].names)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
195 else:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
196 self.names = []
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
197 if isinstance(source.value, (ast.List, ast.Tuple)):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
198 for node in source.value.elts:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
199 if isinstance(node, ast.Str):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
200 self.names.append(node.s)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
201 super(ExportBinding, self).__init__(name, source)
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
202
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 802
diff changeset
203
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
204 class Scope(dict):
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
205 importStarred = False # set to True when import * is found
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
206
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
207 def __repr__(self):
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
208 scope_cls = self.__class__.__name__
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
209 return '<%s at 0x%x %s>' % (scope_cls, id(self), dict.__repr__(self))
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
210
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 802
diff changeset
211
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
212 class ClassScope(Scope):
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
213 pass
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
214
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 802
diff changeset
215
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
216 class FunctionScope(Scope):
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
217 """
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
218 I represent a name scope for a function.
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
219
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
220 @ivar globals: Names declared 'global' in this function.
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
221 """
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
222 usesLocals = False
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
223 alwaysUsed = set(['__tracebackhide__',
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
224 '__traceback_info__', '__traceback_supplement__'])
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
225
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
226 def __init__(self):
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
227 super(FunctionScope, self).__init__()
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
228 # Simplify: manage the special locals as globals
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
229 self.globals = self.alwaysUsed.copy()
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
230 self.returnValue = None # First non-empty return
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
231 self.isGenerator = False # Detect a generator
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
232
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
233 def unusedAssignments(self):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
234 """
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
235 Return a generator for the assignments which have not been used.
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
236 """
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
237 for name, binding in self.items():
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
238 if (not binding.used and name not in self.globals
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
239 and not self.usesLocals
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
240 and isinstance(binding, Assignment)):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
241 yield name, binding
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
242
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
243
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
244 class GeneratorScope(Scope):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
245 pass
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
246
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 802
diff changeset
247
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
248 class ModuleScope(Scope):
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
249 pass
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
250
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
251
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
252 # Globally defined names which are not attributes of the builtins module, or
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
253 # are only present on some platforms.
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
254 _MAGIC_GLOBALS = ['__file__', '__builtins__', 'WindowsError']
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
255
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
256
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
257 def getNodeName(node):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
258 # Returns node.id, or node.name, or None
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
259 if hasattr(node, 'id'): # One of the many nodes with an id
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
260 return node.id
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
261 if hasattr(node, 'name'): # a ExceptHandler node
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
262 return node.name
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
263
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 802
diff changeset
264
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
265 class Checker(object):
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
266 """
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
267 I check the cleanliness and sanity of Python code.
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
268
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
269 @ivar _deferredFunctions: Tracking list used by L{deferFunction}. Elements
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
270 of the list are two-tuples. The first element is the callable passed
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
271 to L{deferFunction}. The second element is a copy of the scope stack
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
272 at the time L{deferFunction} was called.
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
273
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
274 @ivar _deferredAssignments: Similar to C{_deferredFunctions}, but for
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
275 callables which are deferred assignment checks.
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
276 """
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
277
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
278 nodeDepth = 0
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
279 offset = None
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
280 traceTree = False
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
281
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
282 builtIns = set(builtin_vars).union(_MAGIC_GLOBALS)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
283 _customBuiltIns = os.environ.get('PYFLAKES_BUILTINS')
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
284 if _customBuiltIns:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
285 builtIns.update(_customBuiltIns.split(','))
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
286 del _customBuiltIns
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
287
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
288 def __init__(self, tree, filename='(none)', builtins=None,
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
289 withDoctest='PYFLAKES_NODOCTEST' not in os.environ):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
290 self._nodeHandlers = {}
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
291 self._deferredFunctions = []
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
292 self._deferredAssignments = []
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
293 self.deadScopes = []
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
294 self.messages = []
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
295 self.filename = filename
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
296 if builtins:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
297 self.builtIns = self.builtIns.union(builtins)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
298 self.withDoctest = withDoctest
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
299 self.scopeStack = [ModuleScope()]
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
300 self.exceptHandlers = [()]
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
301 self.futuresAllowed = True
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
302
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
303 ## added for eric5
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
304 if isinstance(tree, basestring):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
305 tree = compile(tree, filename, "exec", ast.PyCF_ONLY_AST)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
306 ## end added for eric5
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
307 self.root = tree
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
308 self.handleChildren(tree)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
309 self.runDeferred(self._deferredFunctions)
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
310 # Set _deferredFunctions to None so that deferFunction will fail
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
311 # noisily if called after we've run through the deferred functions.
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
312 self._deferredFunctions = None
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
313 self.runDeferred(self._deferredAssignments)
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
314 # Set _deferredAssignments to None so that deferAssignment will fail
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
315 # noisily if called after we've run through the deferred assignments.
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
316 self._deferredAssignments = None
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
317 del self.scopeStack[1:]
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
318 self.popScope()
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
319 self.checkDeadScopes()
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
320
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
321 def deferFunction(self, callable):
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
322 """
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
323 Schedule a function handler to be called just before completion.
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
324
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
325 This is used for handling function bodies, which must be deferred
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
326 because code later in the file might modify the global scope. When
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
327 `callable` is called, the scope at the time this is called will be
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
328 restored, however it will contain any new bindings added to it.
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
329 """
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
330 self._deferredFunctions.append((callable, self.scopeStack[:], self.offset))
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
331
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
332 def deferAssignment(self, callable):
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
333 """
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
334 Schedule an assignment handler to be called just after deferred
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
335 function handlers.
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
336 """
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
337 self._deferredAssignments.append((callable, self.scopeStack[:], self.offset))
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
338
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
339 def runDeferred(self, deferred):
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
340 """
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
341 Run the callables in C{deferred} using their associated scope stack.
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
342 """
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
343 for handler, scope, offset in deferred:
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
344 self.scopeStack = scope
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
345 self.offset = offset
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
346 handler()
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
347
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
348 @property
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
349 def scope(self):
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
350 return self.scopeStack[-1]
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
351
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
352 def popScope(self):
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
353 self.deadScopes.append(self.scopeStack.pop())
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
354
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
355 def checkDeadScopes(self):
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
356 """
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
357 Look at scopes which have been fully examined and report names in them
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
358 which were imported but unused.
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
359 """
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
360 for scope in self.deadScopes:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
361 if isinstance(scope.get('__all__'), ExportBinding):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
362 all_names = set(scope['__all__'].names)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
363 if not scope.importStarred and \
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
364 os.path.basename(self.filename) != '__init__.py':
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
365 # Look for possible mistakes in the export list
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
366 undefined = all_names.difference(scope)
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
367 for name in undefined:
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
368 self.report(messages.UndefinedExport,
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
369 scope['__all__'].source, name)
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
370 else:
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
371 all_names = []
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
372
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
373 # Look for imported names that aren't used.
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
374 for value in scope.values():
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
375 if isinstance(value, Importation):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
376 used = value.used or value.name in all_names
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
377 if not used:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
378 messg = messages.UnusedImport
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
379 self.report(messg, value.source, value.name)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
380 for node in value.redefined:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
381 if isinstance(self.getParent(node), ast.For):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
382 messg = messages.ImportShadowedByLoopVar
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
383 elif used:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
384 continue
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
385 else:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
386 messg = messages.RedefinedWhileUnused
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
387 self.report(messg, node, value.name, value.source)
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
388
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
389 def pushScope(self, scopeClass=FunctionScope):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
390 self.scopeStack.append(scopeClass())
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
391
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
392 def report(self, messageClass, *args, **kwargs):
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
393 self.messages.append(messageClass(self.filename, *args, **kwargs))
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
394
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
395 def getParent(self, node):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
396 # Lookup the first parent which is not Tuple, List or Starred
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
397 while True:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
398 node = node.parent
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
399 if not hasattr(node, 'elts') and not hasattr(node, 'ctx'):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
400 return node
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
401
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
402 def getCommonAncestor(self, lnode, rnode, stop):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
403 if stop in (lnode, rnode) or not (hasattr(lnode, 'parent') and
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
404 hasattr(rnode, 'parent')):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
405 return None
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
406 if lnode is rnode:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
407 return lnode
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
408
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
409 if (lnode.depth > rnode.depth):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
410 return self.getCommonAncestor(lnode.parent, rnode, stop)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
411 if (lnode.depth < rnode.depth):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
412 return self.getCommonAncestor(lnode, rnode.parent, stop)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
413 return self.getCommonAncestor(lnode.parent, rnode.parent, stop)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
414
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
415 def descendantOf(self, node, ancestors, stop):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
416 for a in ancestors:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
417 if self.getCommonAncestor(node, a, stop):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
418 return True
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
419 return False
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
420
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
421 def differentForks(self, lnode, rnode):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
422 """True, if lnode and rnode are located on different forks of IF/TRY"""
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
423 ancestor = self.getCommonAncestor(lnode, rnode, self.root)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
424 parts = getAlternatives(ancestor)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
425 if parts:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
426 for items in parts:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
427 if self.descendantOf(lnode, items, ancestor) ^ \
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
428 self.descendantOf(rnode, items, ancestor):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
429 return True
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
430 return False
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
431
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
432 def addBinding(self, node, value):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
433 """
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
434 Called when a binding is altered.
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
435
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
436 - `node` is the statement responsible for the change
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
437 - `value` is the new value, a Binding instance
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
438 """
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
439 # assert value.source in (node, node.parent):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
440 for scope in self.scopeStack[::-1]:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
441 if value.name in scope:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
442 break
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
443 existing = scope.get(value.name)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
444
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
445 if existing and not self.differentForks(node, existing.source):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
446
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
447 parent_stmt = self.getParent(value.source)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
448 if isinstance(existing, Importation) and isinstance(parent_stmt, ast.For):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
449 self.report(messages.ImportShadowedByLoopVar,
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
450 node, value.name, existing.source)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
451
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
452 elif scope is self.scope:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
453 if (isinstance(parent_stmt, ast.comprehension) and
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
454 not isinstance(self.getParent(existing.source),
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
455 (ast.For, ast.comprehension))):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
456 self.report(messages.RedefinedInListComp,
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
457 node, value.name, existing.source)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
458 elif not existing.used and value.redefines(existing):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
459 self.report(messages.RedefinedWhileUnused,
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
460 node, value.name, existing.source)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
461
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
462 elif isinstance(existing, Importation) and value.redefines(existing):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
463 existing.redefined.append(node)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
464
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
465 self.scope[value.name] = value
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
466
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
467 def getNodeHandler(self, node_class):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
468 try:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
469 return self._nodeHandlers[node_class]
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
470 except KeyError:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
471 nodeType = getNodeType(node_class)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
472 self._nodeHandlers[node_class] = handler = getattr(self, nodeType)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
473 return handler
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
474
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
475 def handleNodeLoad(self, node):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
476 name = getNodeName(node)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
477 if not name:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
478 return
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
479 # try local scope
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
480 try:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
481 self.scope[name].used = (self.scope, node)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
482 except KeyError:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
483 pass
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
484 else:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
485 return
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
486
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
487 scopes = [scope for scope in self.scopeStack[:-1]
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
488 if isinstance(scope, (FunctionScope, ModuleScope))]
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
489 if isinstance(self.scope, GeneratorScope) and scopes[-1] != self.scopeStack[-2]:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
490 scopes.append(self.scopeStack[-2])
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
491
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
492 # try enclosing function scopes and global scope
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
493 importStarred = self.scope.importStarred
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
494 for scope in reversed(scopes):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
495 importStarred = importStarred or scope.importStarred
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
496 try:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
497 scope[name].used = (self.scope, node)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
498 except KeyError:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
499 pass
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
500 else:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
501 return
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
502
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
503 # look in the built-ins
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
504 if importStarred or name in self.builtIns:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
505 return
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
506 if name == '__path__' and os.path.basename(self.filename) == '__init__.py':
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
507 # the special name __path__ is valid only in packages
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
508 return
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
509
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
510 # protected with a NameError handler?
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
511 if 'NameError' not in self.exceptHandlers[-1]:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
512 self.report(messages.UndefinedName, node, name)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
513
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
514 def handleNodeStore(self, node):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
515 name = getNodeName(node)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
516 if not name:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
517 return
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
518 # if the name hasn't already been defined in the current scope
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
519 if isinstance(self.scope, FunctionScope) and name not in self.scope:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
520 # for each function or module scope above us
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
521 for scope in self.scopeStack[:-1]:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
522 if not isinstance(scope, (FunctionScope, ModuleScope)):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
523 continue
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
524 # if the name was defined in that scope, and the name has
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
525 # been accessed already in the current scope, and hasn't
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
526 # been declared global
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
527 used = name in scope and scope[name].used
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
528 if used and used[0] is self.scope and name not in self.scope.globals:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
529 # then it's probably a mistake
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
530 self.report(messages.UndefinedLocal,
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
531 scope[name].used[1], name, scope[name].source)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
532 break
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
533
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
534 parent_stmt = self.getParent(node)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
535 if isinstance(parent_stmt, (ast.For, ast.comprehension)) or (
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
536 parent_stmt != node.parent and
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
537 not self.isLiteralTupleUnpacking(parent_stmt)):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
538 binding = Binding(name, node)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
539 elif name == '__all__' and isinstance(self.scope, ModuleScope):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
540 binding = ExportBinding(name, node.parent, self.scope)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
541 else:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
542 binding = Assignment(name, node)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
543 if name in self.scope:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
544 binding.used = self.scope[name].used
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
545 self.addBinding(node, binding)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
546
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
547 def handleNodeDelete(self, node):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
548 name = getNodeName(node)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
549 if not name:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
550 return
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
551 if isinstance(self.scope, FunctionScope) and name in self.scope.globals:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
552 self.scope.globals.remove(name)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
553 else:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
554 try:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
555 del self.scope[name]
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
556 except KeyError:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
557 self.report(messages.UndefinedName, node, name)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
558
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
559 def handleChildren(self, tree, omit=None):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
560 for node in iter_child_nodes(tree, omit=omit):
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
561 self.handleNode(node, tree)
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
562
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
563 def isLiteralTupleUnpacking(self, node):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
564 if isinstance(node, ast.Assign):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
565 for child in node.targets + [node.value]:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
566 if not hasattr(child, 'elts'):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
567 return False
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
568 return True
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
569
1535
f2650ea19bb8 Migrated py2flakes to v0.5.0 in order to fix issues for Python 2.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
570 def isDocstring(self, node):
f2650ea19bb8 Migrated py2flakes to v0.5.0 in order to fix issues for Python 2.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
571 """
f2650ea19bb8 Migrated py2flakes to v0.5.0 in order to fix issues for Python 2.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
572 Determine if the given node is a docstring, as long as it is at the
f2650ea19bb8 Migrated py2flakes to v0.5.0 in order to fix issues for Python 2.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
573 correct place in the node tree.
f2650ea19bb8 Migrated py2flakes to v0.5.0 in order to fix issues for Python 2.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
574 """
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
575 return isinstance(node, ast.Str) or (isinstance(node, ast.Expr) and
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
576 isinstance(node.value, ast.Str))
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
577
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
578 def getDocstring(self, node):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
579 if isinstance(node, ast.Expr):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
580 node = node.value
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
581 if not isinstance(node, ast.Str):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
582 return (None, None)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
583 # Computed incorrectly if the docstring has backslash
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
584 doctest_lineno = node.lineno - node.s.count('\n') - 1
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
585 return (node.s, doctest_lineno)
1535
f2650ea19bb8 Migrated py2flakes to v0.5.0 in order to fix issues for Python 2.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
586
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
587 def handleNode(self, node, parent):
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
588 if node is None:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
589 return
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
590 if self.offset and getattr(node, 'lineno', None) is not None:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
591 node.lineno += self.offset[0]
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
592 node.col_offset += self.offset[1]
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
593 if self.traceTree:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
594 print(' ' * self.nodeDepth + node.__class__.__name__)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
595 if self.futuresAllowed and not (isinstance(node, ast.ImportFrom) or
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
596 self.isDocstring(node)):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
597 self.futuresAllowed = False
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
598 self.nodeDepth += 1
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
599 node.depth = self.nodeDepth
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
600 node.parent = parent
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
601 try:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
602 handler = self.getNodeHandler(node.__class__)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
603 handler(node)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
604 finally:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
605 self.nodeDepth -= 1
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
606 if self.traceTree:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
607 print(' ' * self.nodeDepth + 'end ' + node.__class__.__name__)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
608
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
609 _getDoctestExamples = doctest.DocTestParser().get_examples
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
610
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
611 def handleDoctests(self, node):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
612 try:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
613 (docstring, node_lineno) = self.getDocstring(node.body[0])
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
614 examples = docstring and self._getDoctestExamples(docstring)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
615 except (ValueError, IndexError):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
616 # e.g. line 6 of the docstring for <string> has inconsistent
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
617 # leading whitespace: ...
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
618 return
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
619 if not examples:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
620 return
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
621 node_offset = self.offset or (0, 0)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
622 self.pushScope()
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
623 underscore_in_builtins = '_' in self.builtIns
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
624 if not underscore_in_builtins:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
625 self.builtIns.add('_')
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
626 for example in examples:
2088
73a2ca4ac409 Added code to handle unknown node types to the pyflakes checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1544
diff changeset
627 try:
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
628 tree = compile(example.source, "<doctest>", "exec", ast.PyCF_ONLY_AST)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
629 except SyntaxError:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
630 e = sys.exc_info()[1]
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
631 position = (node_lineno + example.lineno + e.lineno,
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
632 example.indent + 4 + (e.offset or 0))
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
633 self.report(messages.DoctestSyntaxError, node, position)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
634 else:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
635 self.offset = (node_offset[0] + node_lineno + example.lineno,
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
636 node_offset[1] + example.indent + 4)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
637 self.handleChildren(tree)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
638 self.offset = node_offset
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
639 if not underscore_in_builtins:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
640 self.builtIns.remove('_')
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
641 self.popScope()
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
642
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
643 def ignore(self, node):
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
644 pass
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
645
1535
f2650ea19bb8 Migrated py2flakes to v0.5.0 in order to fix issues for Python 2.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
646 # "stmt" type nodes
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
647 DELETE = PRINT = FOR = WHILE = IF = WITH = WITHITEM = RAISE = \
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
648 TRYFINALLY = ASSERT = EXEC = EXPR = ASSIGN = handleChildren
1535
f2650ea19bb8 Migrated py2flakes to v0.5.0 in order to fix issues for Python 2.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
649
f2650ea19bb8 Migrated py2flakes to v0.5.0 in order to fix issues for Python 2.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
650 CONTINUE = BREAK = PASS = ignore
f2650ea19bb8 Migrated py2flakes to v0.5.0 in order to fix issues for Python 2.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
651
f2650ea19bb8 Migrated py2flakes to v0.5.0 in order to fix issues for Python 2.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
652 # "expr" type nodes
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
653 BOOLOP = BINOP = UNARYOP = IFEXP = DICT = SET = \
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
654 COMPARE = CALL = REPR = ATTRIBUTE = SUBSCRIPT = LIST = TUPLE = \
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
655 STARRED = NAMECONSTANT = handleChildren
1535
f2650ea19bb8 Migrated py2flakes to v0.5.0 in order to fix issues for Python 2.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
656
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
657 NUM = STR = BYTES = ELLIPSIS = ignore
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
658
1535
f2650ea19bb8 Migrated py2flakes to v0.5.0 in order to fix issues for Python 2.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
659 # "slice" type nodes
f2650ea19bb8 Migrated py2flakes to v0.5.0 in order to fix issues for Python 2.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
660 SLICE = EXTSLICE = INDEX = handleChildren
f2650ea19bb8 Migrated py2flakes to v0.5.0 in order to fix issues for Python 2.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
661
f2650ea19bb8 Migrated py2flakes to v0.5.0 in order to fix issues for Python 2.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
662 # expression contexts are node instances too, though being constants
f2650ea19bb8 Migrated py2flakes to v0.5.0 in order to fix issues for Python 2.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
663 LOAD = STORE = DEL = AUGLOAD = AUGSTORE = PARAM = ignore
f2650ea19bb8 Migrated py2flakes to v0.5.0 in order to fix issues for Python 2.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
664
f2650ea19bb8 Migrated py2flakes to v0.5.0 in order to fix issues for Python 2.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
665 # same for operators
f2650ea19bb8 Migrated py2flakes to v0.5.0 in order to fix issues for Python 2.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
666 AND = OR = ADD = SUB = MULT = DIV = MOD = POW = LSHIFT = RSHIFT = \
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
667 BITOR = BITXOR = BITAND = FLOORDIV = INVERT = NOT = UADD = USUB = \
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
668 EQ = NOTEQ = LT = LTE = GT = GTE = IS = ISNOT = IN = NOTIN = ignore
1535
f2650ea19bb8 Migrated py2flakes to v0.5.0 in order to fix issues for Python 2.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
669
f2650ea19bb8 Migrated py2flakes to v0.5.0 in order to fix issues for Python 2.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
670 # additional node types
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
671 LISTCOMP = COMPREHENSION = KEYWORD = handleChildren
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
672
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
673 def GLOBAL(self, node):
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
674 """
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
675 Keep track of globals declarations.
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
676 """
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
677 if isinstance(self.scope, FunctionScope):
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
678 self.scope.globals.update(node.names)
1535
f2650ea19bb8 Migrated py2flakes to v0.5.0 in order to fix issues for Python 2.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
679
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
680 NONLOCAL = GLOBAL
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
681
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
682 def GENERATOREXP(self, node):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
683 self.pushScope(GeneratorScope)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
684 self.handleChildren(node)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
685 self.popScope()
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 802
diff changeset
686
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
687 DICTCOMP = SETCOMP = GENERATOREXP
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
688
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
689 def NAME(self, node):
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
690 """
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
691 Handle occurrence of Name (which can be a load/store/delete access.)
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
692 """
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
693 # Locate the name in locals / function / globals scopes.
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
694 if isinstance(node.ctx, (ast.Load, ast.AugLoad)):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
695 self.handleNodeLoad(node)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
696 if (node.id == 'locals' and isinstance(self.scope, FunctionScope)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
697 and isinstance(node.parent, ast.Call)):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
698 # we are doing locals() call in current scope
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
699 self.scope.usesLocals = True
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
700 elif isinstance(node.ctx, (ast.Store, ast.AugStore)):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
701 self.handleNodeStore(node)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
702 elif isinstance(node.ctx, ast.Del):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
703 self.handleNodeDelete(node)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
704 else:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
705 # must be a Param context -- this only happens for names in function
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
706 # arguments, but these aren't dispatched through here
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
707 raise RuntimeError("Got impossible expression context: %r" % (node.ctx,))
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
708
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
709 def RETURN(self, node):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
710 if node.value and not self.scope.returnValue:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
711 self.scope.returnValue = node.value
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
712 self.handleNode(node.value, node)
1535
f2650ea19bb8 Migrated py2flakes to v0.5.0 in order to fix issues for Python 2.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
713
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
714 def YIELD(self, node):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
715 self.scope.isGenerator = True
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
716 self.handleNode(node.value, node)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
717
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
718 YIELDFROM = YIELD
1535
f2650ea19bb8 Migrated py2flakes to v0.5.0 in order to fix issues for Python 2.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
719
f2650ea19bb8 Migrated py2flakes to v0.5.0 in order to fix issues for Python 2.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
720 def FUNCTIONDEF(self, node):
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
721 for deco in node.decorator_list:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
722 self.handleNode(deco, node)
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
723 self.LAMBDA(node)
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
724 self.addBinding(node, FunctionDefinition(node.name, node))
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
725 if self.withDoctest:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
726 self.deferFunction(lambda: self.handleDoctests(node))
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
727
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
728 def LAMBDA(self, node):
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
729 args = []
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
730 annotations = []
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
731
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
732 if PY2:
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
733 def addArgs(arglist):
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
734 for arg in arglist:
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
735 if isinstance(arg, ast.Tuple):
1535
f2650ea19bb8 Migrated py2flakes to v0.5.0 in order to fix issues for Python 2.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
736 addArgs(arg.elts)
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
737 else:
1535
f2650ea19bb8 Migrated py2flakes to v0.5.0 in order to fix issues for Python 2.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
738 args.append(arg.id)
f2650ea19bb8 Migrated py2flakes to v0.5.0 in order to fix issues for Python 2.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
739 addArgs(node.args.args)
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
740 defaults = node.args.defaults
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
741 else:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
742 for arg in node.args.args + node.args.kwonlyargs:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
743 args.append(arg.arg)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
744 annotations.append(arg.annotation)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
745 defaults = node.args.defaults + node.args.kw_defaults
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
746
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
747 # Only for Python3 FunctionDefs
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
748 is_py3_func = hasattr(node, 'returns')
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
749
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
750 for arg_name in ('vararg', 'kwarg'):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
751 wildcard = getattr(node.args, arg_name)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
752 if not wildcard:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
753 continue
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
754 args.append(wildcard if PY33 else wildcard.arg)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
755 if is_py3_func:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
756 if PY33: # Python 2.5 to 3.3
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
757 argannotation = arg_name + 'annotation'
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
758 annotations.append(getattr(node.args, argannotation))
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
759 else: # Python >= 3.4
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
760 annotations.append(wildcard.annotation)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
761
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
762 if is_py3_func:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
763 annotations.append(node.returns)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
764
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
765 if len(set(args)) < len(args):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
766 for (idx, arg) in enumerate(args):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
767 if arg in args[:idx]:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
768 self.report(messages.DuplicateArgument, node, arg)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
769
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
770 for child in annotations + defaults:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
771 if child:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
772 self.handleNode(child, node)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
773
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
774 def runFunction():
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
775
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
776 self.pushScope()
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
777 for name in args:
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
778 self.addBinding(node, Argument(name, node))
1535
f2650ea19bb8 Migrated py2flakes to v0.5.0 in order to fix issues for Python 2.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
779 if isinstance(node.body, list):
f2650ea19bb8 Migrated py2flakes to v0.5.0 in order to fix issues for Python 2.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
780 # case for FunctionDefs
f2650ea19bb8 Migrated py2flakes to v0.5.0 in order to fix issues for Python 2.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
781 for stmt in node.body:
f2650ea19bb8 Migrated py2flakes to v0.5.0 in order to fix issues for Python 2.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
782 self.handleNode(stmt, node)
f2650ea19bb8 Migrated py2flakes to v0.5.0 in order to fix issues for Python 2.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
783 else:
f2650ea19bb8 Migrated py2flakes to v0.5.0 in order to fix issues for Python 2.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
784 # case for Lambdas
f2650ea19bb8 Migrated py2flakes to v0.5.0 in order to fix issues for Python 2.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
785 self.handleNode(node.body, node)
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 802
diff changeset
786
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
787 def checkUnusedAssignments():
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
788 """
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
789 Check to see if any assignments have not been used.
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
790 """
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
791 for name, binding in self.scope.unusedAssignments():
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
792 self.report(messages.UnusedVariable, binding.source, name)
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
793 self.deferAssignment(checkUnusedAssignments)
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
794
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
795 if PY32:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
796 def checkReturnWithArgumentInsideGenerator():
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
797 """
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
798 Check to see if there is any return statement with
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
799 arguments but the function is a generator.
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
800 """
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
801 if self.scope.isGenerator and self.scope.returnValue:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
802 self.report(messages.ReturnWithArgsInsideGenerator,
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
803 self.scope.returnValue)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
804 self.deferAssignment(checkReturnWithArgumentInsideGenerator)
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
805 self.popScope()
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
806
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
807 self.deferFunction(runFunction)
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
808
1535
f2650ea19bb8 Migrated py2flakes to v0.5.0 in order to fix issues for Python 2.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
809 def CLASSDEF(self, node):
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
810 """
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
811 Check names used in a class definition, including its decorators, base
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
812 classes, and the body of its definition. Additionally, add its name to
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
813 the current scope.
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
814 """
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
815 for deco in node.decorator_list:
1535
f2650ea19bb8 Migrated py2flakes to v0.5.0 in order to fix issues for Python 2.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
816 self.handleNode(deco, node)
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
817 for baseNode in node.bases:
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
818 self.handleNode(baseNode, node)
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
819 if not PY2:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
820 for keywordNode in node.keywords:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
821 self.handleNode(keywordNode, node)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
822 self.pushScope(ClassScope)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
823 if self.withDoctest:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
824 self.deferFunction(lambda: self.handleDoctests(node))
1535
f2650ea19bb8 Migrated py2flakes to v0.5.0 in order to fix issues for Python 2.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
825 for stmt in node.body:
f2650ea19bb8 Migrated py2flakes to v0.5.0 in order to fix issues for Python 2.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
826 self.handleNode(stmt, node)
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
827 self.popScope()
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
828 self.addBinding(node, ClassDefinition(node.name, node))
1535
f2650ea19bb8 Migrated py2flakes to v0.5.0 in order to fix issues for Python 2.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
829
f2650ea19bb8 Migrated py2flakes to v0.5.0 in order to fix issues for Python 2.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
830 def AUGASSIGN(self, node):
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
831 self.handleNodeLoad(node.target)
1535
f2650ea19bb8 Migrated py2flakes to v0.5.0 in order to fix issues for Python 2.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
832 self.handleNode(node.value, node)
f2650ea19bb8 Migrated py2flakes to v0.5.0 in order to fix issues for Python 2.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
833 self.handleNode(node.target, node)
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
834
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
835 def IMPORT(self, node):
1535
f2650ea19bb8 Migrated py2flakes to v0.5.0 in order to fix issues for Python 2.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
836 for alias in node.names:
f2650ea19bb8 Migrated py2flakes to v0.5.0 in order to fix issues for Python 2.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
837 name = alias.asname or alias.name
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
838 importation = Importation(name, node)
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
839 self.addBinding(node, importation)
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
840
1535
f2650ea19bb8 Migrated py2flakes to v0.5.0 in order to fix issues for Python 2.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
841 def IMPORTFROM(self, node):
f2650ea19bb8 Migrated py2flakes to v0.5.0 in order to fix issues for Python 2.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
842 if node.module == '__future__':
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
843 if not self.futuresAllowed:
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
844 self.report(messages.LateFutureImport,
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
845 node, [n.name for n in node.names])
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
846 else:
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
847 self.futuresAllowed = False
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
848
1535
f2650ea19bb8 Migrated py2flakes to v0.5.0 in order to fix issues for Python 2.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
849 for alias in node.names:
f2650ea19bb8 Migrated py2flakes to v0.5.0 in order to fix issues for Python 2.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
850 if alias.name == '*':
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
851 self.scope.importStarred = True
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
852 self.report(messages.ImportStarUsed, node, node.module)
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
853 continue
1535
f2650ea19bb8 Migrated py2flakes to v0.5.0 in order to fix issues for Python 2.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
854 name = alias.asname or alias.name
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
855 importation = Importation(name, node)
1535
f2650ea19bb8 Migrated py2flakes to v0.5.0 in order to fix issues for Python 2.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
856 if node.module == '__future__':
3551
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
857 importation.used = (self.scope, node)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
858 self.addBinding(node, importation)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
859
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
860 def TRY(self, node):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
861 handler_names = []
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
862 # List the exception handlers
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
863 for handler in node.handlers:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
864 if isinstance(handler.type, ast.Tuple):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
865 for exc_type in handler.type.elts:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
866 handler_names.append(getNodeName(exc_type))
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
867 elif handler.type:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
868 handler_names.append(getNodeName(handler.type))
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
869 # Memorize the except handlers and process the body
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
870 self.exceptHandlers.append(handler_names)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
871 for child in node.body:
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
872 self.handleNode(child, node)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
873 self.exceptHandlers.pop()
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
874 # Process the other nodes: "except:", "else:", "finally:"
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
875 self.handleChildren(node, omit='body')
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
876
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
877 TRYEXCEPT = TRY
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
878
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
879 def EXCEPTHANDLER(self, node):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
880 # 3.x: in addition to handling children, we must handle the name of
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
881 # the exception, which is not a Name node, but a simple string.
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
882 if isinstance(node.name, str):
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
883 self.handleNodeStore(node)
d608f3f42d71 updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3160
diff changeset
884 self.handleChildren(node)
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
885
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
886 #
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
887 # eflag: FileType = Python2

eric ide

mercurial