src/eric7/Plugins/CheckerPlugins/SyntaxChecker/pyflakes/checker.py

Thu, 08 Dec 2022 16:01:34 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Thu, 08 Dec 2022 16:01:34 +0100
branch
eric7
changeset 9593
89f885d857e4
parent 9376
e143a7e7254b
child 9653
e67609152c5e
permissions
-rw-r--r--

Third Party packages
- Upgraded pyflakes to version 3.0.1.

2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
2
8881
54e42bc2437a Updated copyright for 2022.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8682
diff changeset
3 # Copyright (c) 2010 - 2022 Detlev Offenbach <detlev@die-offenbachs.de>
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
4 #
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
5 # Original (c) 2005-2010 Divmod, Inc.
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
6 #
7960
e8fc383322f7 Harmonized some user visible strings and changed the term 'eric6' to the more generic 'eric'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
7 # This module is based on pyflakes but was modified to work with eric
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
8 """
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
9 Main module.
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
10
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
11 Implement the central Checker class.
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
12 Also, it models the Bindings and Scopes.
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
13 """
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
14 import __future__
9376
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
15 import builtins
6353
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
16 import ast
7617
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
17 import contextlib
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
18 import doctest
6742
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
19 import functools
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
20 import os
6742
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
21 import re
7395
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
22 import string
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
23 import sys
9593
89f885d857e4 Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9376
diff changeset
24 import warnings
6742
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
25
9593
89f885d857e4 Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9376
diff changeset
26 from pyflakes import messages
3544
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
27
6742
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
28 PY38_PLUS = sys.version_info >= (3, 8)
9376
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
29 PYPY = hasattr(sys, 'pypy_version_info')
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
30
9376
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
31 builtin_vars = dir(builtins)
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
32
7395
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
33 parse_format_string = string.Formatter().parse
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
34
6353
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
35
9376
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
36 def getAlternatives(n):
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
37 if isinstance(n, ast.If):
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
38 return [n.body]
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
39 if isinstance(n, ast.Try):
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
40 return [n.body + n.orelse] + [[hdl] for hdl in n.handlers]
3544
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
41
6742
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
42
9376
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
43 FOR_TYPES = (ast.For, ast.AsyncFor)
7617
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
44
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
45 if PY38_PLUS:
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
46 def _is_singleton(node): # type: (ast.AST) -> bool
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
47 return (
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
48 isinstance(node, ast.Constant) and
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
49 isinstance(node.value, (bool, type(Ellipsis), type(None)))
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
50 )
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
51 else:
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
52 def _is_singleton(node): # type: (ast.AST) -> bool
9376
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
53 return isinstance(node, (ast.NameConstant, ast.Ellipsis))
7617
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
54
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
55
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
56 def _is_tuple_constant(node): # type: (ast.AST) -> bool
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
57 return (
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
58 isinstance(node, ast.Tuple) and
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
59 all(_is_constant(elt) for elt in node.elts)
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
60 )
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
61
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
62
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
63 if PY38_PLUS:
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
64 def _is_constant(node):
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
65 return isinstance(node, ast.Constant) or _is_tuple_constant(node)
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
66 else:
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
67 def _is_constant(node):
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
68 return (
9376
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
69 isinstance(node, (ast.Str, ast.Num, ast.Bytes)) or
7617
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
70 _is_singleton(node) or
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
71 _is_tuple_constant(node)
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
72 )
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
73
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
74
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
75 def _is_const_non_singleton(node): # type: (ast.AST) -> bool
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
76 return _is_constant(node) and not _is_singleton(node)
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
77
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
78
9376
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
79 def _is_name_or_attr(node, name): # type: (ast.AST, str) -> bool
8208
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
80 return (
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
81 (isinstance(node, ast.Name) and node.id == name) or
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
82 (isinstance(node, ast.Attribute) and node.attr == name)
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
83 )
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
84
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
85
7395
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
86 MAPPING_KEY_RE = re.compile(r'\(([^()]*)\)')
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
87 CONVERSION_FLAG_RE = re.compile('[#0+ -]*')
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
88 WIDTH_RE = re.compile(r'(?:\*|\d*)')
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
89 PRECISION_RE = re.compile(r'(?:\.(?:\*|\d*))?')
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
90 LENGTH_RE = re.compile('[hlL]?')
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
91 # https://docs.python.org/3/library/stdtypes.html#old-string-formatting
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
92 VALID_CONVERSIONS = frozenset('diouxXeEfFgGcrsa%')
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
93
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
94
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
95 def _must_match(regex, string, pos):
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
96 match = regex.match(string, pos)
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
97 assert match is not None
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
98 return match
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
99
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
100
9376
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
101 def parse_percent_format(s):
7395
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
102 """Parses the string component of a `'...' % ...` format call
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
103
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
104 Copied from https://github.com/asottile/pyupgrade at v1.20.1
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
105 """
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
106
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
107 def _parse_inner():
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
108 string_start = 0
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
109 string_end = 0
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
110 in_fmt = False
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
111
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
112 i = 0
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
113 while i < len(s):
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
114 if not in_fmt:
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
115 try:
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
116 i = s.index('%', i)
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
117 except ValueError: # no more % fields!
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
118 yield s[string_start:], None
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
119 return
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
120 else:
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
121 string_end = i
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
122 i += 1
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
123 in_fmt = True
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
124 else:
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
125 key_match = MAPPING_KEY_RE.match(s, i)
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
126 if key_match:
9376
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
127 key = key_match.group(1)
7395
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
128 i = key_match.end()
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
129 else:
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
130 key = None
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
131
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
132 conversion_flag_match = _must_match(CONVERSION_FLAG_RE, s, i)
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
133 conversion_flag = conversion_flag_match.group() or None
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
134 i = conversion_flag_match.end()
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
135
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
136 width_match = _must_match(WIDTH_RE, s, i)
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
137 width = width_match.group() or None
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
138 i = width_match.end()
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
139
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
140 precision_match = _must_match(PRECISION_RE, s, i)
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
141 precision = precision_match.group() or None
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
142 i = precision_match.end()
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
143
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
144 # length modifier is ignored
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
145 i = _must_match(LENGTH_RE, s, i).end()
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
146
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
147 try:
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
148 conversion = s[i]
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
149 except IndexError:
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
150 raise ValueError('end-of-string while parsing format')
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
151 i += 1
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
152
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
153 fmt = (key, conversion_flag, width, precision, conversion)
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
154 yield s[string_start:string_end], fmt
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
155
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
156 in_fmt = False
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
157 string_start = i
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
158
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
159 if in_fmt:
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
160 raise ValueError('end-of-string while parsing format')
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
161
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
162 return tuple(_parse_inner())
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
163
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
164
3544
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
165 class _FieldsOrder(dict):
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
166 """Fix order of AST node fields."""
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
167
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
168 def _get_fields(self, node_class):
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
169 # handle iter before target, and generators before element
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
170 fields = node_class._fields
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
171 if 'iter' in fields:
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
172 key_first = 'iter'.find
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
173 elif 'generators' in fields:
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
174 key_first = 'generators'.find
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
175 else:
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
176 key_first = 'value'.find
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
177 return tuple(sorted(fields, key=key_first, reverse=True))
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
178
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
179 def __missing__(self, node_class):
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
180 self[node_class] = fields = self._get_fields(node_class)
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
181 return fields
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
182
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
183
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
184 def counter(items):
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
185 """
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
186 Simplest required implementation of collections.Counter. Required as 2.6
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
187 does not have Counter in collections.
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
188 """
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
189 results = {}
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
190 for item in items:
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
191 results[item] = results.get(item, 0) + 1
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
192 return results
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
193
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
194
3544
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
195 def iter_child_nodes(node, omit=None, _fields_order=_FieldsOrder()):
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
196 """
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
197 Yield all direct child nodes of *node*, that is, all fields that
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
198 are nodes and all items of fields that are lists of nodes.
6742
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
199
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
200 :param node: AST node to be iterated upon
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
201 :param omit: String or tuple of strings denoting the
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
202 attributes of the node to be omitted from
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
203 further parsing
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
204 :param _fields_order: Order of AST node fields
3544
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
205 """
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
206 for name in _fields_order[node.__class__]:
6742
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
207 if omit and name in omit:
3544
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
208 continue
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
209 field = getattr(node, name, None)
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
210 if isinstance(field, ast.AST):
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
211 yield field
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
212 elif isinstance(field, list):
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
213 for item in field:
8682
04e80d1aaebf Updated pyflakes to 2.4.0 and pycodestyle to 2.8.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 8312
diff changeset
214 if isinstance(item, ast.AST):
04e80d1aaebf Updated pyflakes to 2.4.0 and pycodestyle to 2.8.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 8312
diff changeset
215 yield item
3544
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
216
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
217
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
218 def convert_to_value(item):
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
219 if isinstance(item, ast.Str):
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
220 return item.s
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
221 elif hasattr(ast, 'Bytes') and isinstance(item, ast.Bytes):
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
222 return item.s
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
223 elif isinstance(item, ast.Tuple):
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
224 return tuple(convert_to_value(i) for i in item.elts)
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
225 elif isinstance(item, ast.Num):
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
226 return item.n
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
227 elif isinstance(item, ast.Name):
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
228 result = VariableKey(item=item)
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
229 constants_lookup = {
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
230 'True': True,
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
231 'False': False,
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
232 'None': None,
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
233 }
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
234 return constants_lookup.get(
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
235 result.name,
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
236 result,
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
237 )
9376
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
238 elif isinstance(item, ast.NameConstant):
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
239 return item.value
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
240 else:
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
241 return UnhandledKeyType()
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
242
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
243
6353
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
244 def is_notimplemented_name_node(node):
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
245 return isinstance(node, ast.Name) and getNodeName(node) == 'NotImplemented'
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
246
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
247
9376
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
248 class Binding:
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
249 """
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
250 Represents the binding of a value to a name.
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
251
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
252 The checker uses this to keep track of which names have been bound and
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
253 which names have not. See L{Assignment} for a special type of binding that
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
254 is checked with stricter rules.
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
255
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
256 @ivar used: pair of (L{Scope}, node) indicating the scope and
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
257 the node that this binding was last used.
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
258 """
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
259
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
260 def __init__(self, name, source):
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
261 self.name = name
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
262 self.source = source
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
263 self.used = False
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
264
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
265 def __str__(self):
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
266 return self.name
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
267
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
268 def __repr__(self):
9376
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
269 return '<{} object {!r} from line {!r} at 0x{:x}>'.format(
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
270 self.__class__.__name__,
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
271 self.name,
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
272 self.source.lineno,
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
273 id(self),
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
274 )
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
275
3544
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
276 def redefines(self, other):
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
277 return isinstance(other, Definition) and self.name == other.name
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
278
3544
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
279
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
280 class Definition(Binding):
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
281 """
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
282 A binding that defines a function or a class.
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
283 """
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
284
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
285
6742
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
286 class Builtin(Definition):
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
287 """A definition created for all Python builtins."""
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
288
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
289 def __init__(self, name):
8218
7c09585bd960 Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8208
diff changeset
290 super().__init__(name, None)
6742
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
291
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
292 def __repr__(self):
9376
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
293 return '<{} object {!r} at 0x{:x}>'.format(
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
294 self.__class__.__name__,
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
295 self.name,
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
296 id(self)
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
297 )
6742
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
298
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
299
9376
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
300 class UnhandledKeyType:
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
301 """
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
302 A dictionary key of a type that we cannot or do not check for duplicates.
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
303 """
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
304
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
305
9376
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
306 class VariableKey:
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
307 """
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
308 A dictionary key which is a variable.
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
309
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
310 @ivar item: The variable AST object.
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
311 """
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
312 def __init__(self, item):
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
313 self.name = item.id
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
314
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
315 def __eq__(self, compare):
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
316 return (
6742
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
317 compare.__class__ == self.__class__ and
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
318 compare.name == self.name
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
319 )
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
320
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
321 def __hash__(self):
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
322 return hash(self.name)
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
323
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
324
3544
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
325 class Importation(Definition):
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
326 """
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
327 A binding created by an import statement.
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
328
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
329 @ivar fullName: The complete name given to the import statement,
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
330 possibly including multiple dotted components.
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
331 @type fullName: C{str}
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
332 """
3544
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
333
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
334 def __init__(self, name, source, full_name=None):
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
335 self.fullName = full_name or name
3544
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
336 self.redefined = []
8218
7c09585bd960 Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8208
diff changeset
337 super().__init__(name, source)
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
338
3544
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
339 def redefines(self, other):
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
340 if isinstance(other, SubmoduleImportation):
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
341 # See note in SubmoduleImportation about RedefinedWhileUnused
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
342 return self.fullName == other.fullName
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
343 return isinstance(other, Definition) and self.name == other.name
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
344
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
345 def _has_alias(self):
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
346 """Return whether importation needs an as clause."""
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
347 return not self.fullName.split('.')[-1] == self.name
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
348
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
349 @property
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
350 def source_statement(self):
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
351 """Generate a source statement equivalent to the import."""
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
352 if self._has_alias():
9376
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
353 return f'import {self.fullName} as {self.name}'
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
354 else:
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
355 return 'import %s' % self.fullName
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
356
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
357 def __str__(self):
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
358 """Return import full name with alias."""
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
359 if self._has_alias():
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
360 return self.fullName + ' as ' + self.name
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
361 else:
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
362 return self.fullName
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
363
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
364
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
365 class SubmoduleImportation(Importation):
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
366 """
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
367 A binding created by a submodule import statement.
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
368
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
369 A submodule import is a special case where the root module is implicitly
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
370 imported, without an 'as' clause, and the submodule is also imported.
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
371 Python does not restrict which attributes of the root module may be used.
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
372
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
373 This class is only used when the submodule import is without an 'as' clause.
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
374
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
375 pyflakes handles this case by registering the root module name in the scope,
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
376 allowing any attribute of the root module to be accessed.
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
377
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
378 RedefinedWhileUnused is suppressed in `redefines` unless the submodule
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
379 name is also the same, to avoid false positives.
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
380 """
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
381
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
382 def __init__(self, name, source):
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
383 # A dot should only appear in the name when it is a submodule import
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
384 assert '.' in name and (not source or isinstance(source, ast.Import))
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
385 package_name = name.split('.')[0]
8218
7c09585bd960 Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8208
diff changeset
386 super().__init__(package_name, source)
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
387 self.fullName = name
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
388
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
389 def redefines(self, other):
3544
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
390 if isinstance(other, Importation):
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
391 return self.fullName == other.fullName
8218
7c09585bd960 Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8208
diff changeset
392 return super().redefines(other)
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
393
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
394 def __str__(self):
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
395 return self.fullName
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
396
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
397 @property
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
398 def source_statement(self):
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
399 return 'import ' + self.fullName
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
400
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
401
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
402 class ImportationFrom(Importation):
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
403
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
404 def __init__(self, name, source, module, real_name=None):
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
405 self.module = module
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
406 self.real_name = real_name or name
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
407
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
408 if module.endswith('.'):
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
409 full_name = module + self.real_name
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
410 else:
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
411 full_name = module + '.' + self.real_name
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
412
8218
7c09585bd960 Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8208
diff changeset
413 super().__init__(name, source, full_name)
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
414
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
415 def __str__(self):
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
416 """Return import full name with alias."""
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
417 if self.real_name != self.name:
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
418 return self.fullName + ' as ' + self.name
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
419 else:
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
420 return self.fullName
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
421
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
422 @property
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
423 def source_statement(self):
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
424 if self.real_name != self.name:
9376
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
425 return f'from {self.module} import {self.real_name} as {self.name}'
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
426 else:
9376
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
427 return f'from {self.module} import {self.name}'
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
428
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
429
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
430 class StarImportation(Importation):
5510
cdcd0cd34e79 Upgraded pyflakes to version 1.5.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 5389
diff changeset
431 """A binding created by a 'from x import *' statement."""
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
432
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
433 def __init__(self, name, source):
8218
7c09585bd960 Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8208
diff changeset
434 super().__init__('*', source)
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
435 # Each star importation needs a unique name, and
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
436 # may not be the module name otherwise it will be deemed imported
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
437 self.name = name + '.*'
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
438 self.fullName = name
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
439
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
440 @property
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
441 def source_statement(self):
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
442 return 'from ' + self.fullName + ' import *'
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
443
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
444 def __str__(self):
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
445 # When the module ends with a ., avoid the ambiguous '..*'
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
446 if self.fullName.endswith('.'):
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
447 return self.source_statement
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
448 else:
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
449 return self.name
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
450
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
451
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
452 class FutureImportation(ImportationFrom):
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
453 """
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
454 A binding created by a from `__future__` import statement.
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
455
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
456 `__future__` imports are implicitly used.
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
457 """
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
458
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
459 def __init__(self, name, source, scope):
8218
7c09585bd960 Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8208
diff changeset
460 super().__init__(name, source, '__future__')
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
461 self.used = (scope, source)
3544
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
462
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
463
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
464 class Argument(Binding):
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
465 """
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
466 Represents binding a name as an argument.
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
467 """
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
468
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
469
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
470 class Assignment(Binding):
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
471 """
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
472 Represents binding a name with an explicit assignment.
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
473
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
474 The checker will raise warnings for any Assignment that isn't used. Also,
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
475 the checker does not consider assignments in tuple/list unpacking to be
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
476 Assignments, rather it treats them as simple Bindings.
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
477 """
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
478
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
479
9376
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
480 class NamedExprAssignment(Assignment):
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
481 """
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
482 Represents binding a name with an assignment expression.
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
483 """
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
484
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
485
8208
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
486 class Annotation(Binding):
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
487 """
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
488 Represents binding a name to a type without an associated value.
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
489
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
490 As long as this name is not assigned a value in another binding, it is considered
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
491 undefined for most purposes. One notable exception is using the name as a type
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
492 annotation.
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
493 """
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
494
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
495 def redefines(self, other):
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
496 """An Annotation doesn't define any name, so it cannot redefine one."""
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
497 return False
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
498
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
499
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
500 class FunctionDefinition(Definition):
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
501 pass
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
502
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
503
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
504 class ClassDefinition(Definition):
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
505 pass
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
506
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
507
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
508 class ExportBinding(Binding):
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
509 """
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
510 A binding created by an C{__all__} assignment. If the names in the list
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
511 can be determined statically, they will be treated as names for export and
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
512 additional checking applied to them.
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
513
8208
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
514 The only recognized C{__all__} assignment via list/tuple concatenation is in the
6742
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
515 following format:
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
516
6742
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
517 __all__ = ['a'] + ['b'] + ['c']
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
518
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
519 Names which are imported and not otherwise used but appear in the value of
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
520 C{__all__} will not have an unused import warning reported for them.
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
521 """
3544
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
522
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
523 def __init__(self, name, source, scope):
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
524 if '__all__' in scope and isinstance(source, ast.AugAssign):
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
525 self.names = list(scope['__all__'].names)
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
526 else:
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
527 self.names = []
6742
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
528
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
529 def _add_to_names(container):
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
530 for node in container.elts:
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
531 if isinstance(node, ast.Str):
3544
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
532 self.names.append(node.s)
6742
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
533
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
534 if isinstance(source.value, (ast.List, ast.Tuple)):
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
535 _add_to_names(source.value)
8208
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
536 # If concatenating lists or tuples
6742
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
537 elif isinstance(source.value, ast.BinOp):
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
538 currentValue = source.value
8208
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
539 while isinstance(currentValue.right, (ast.List, ast.Tuple)):
6742
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
540 left = currentValue.left
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
541 right = currentValue.right
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
542 _add_to_names(right)
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
543 # If more lists are being added
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
544 if isinstance(left, ast.BinOp):
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
545 currentValue = left
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
546 # If just two lists are being added
8208
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
547 elif isinstance(left, (ast.List, ast.Tuple)):
6742
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
548 _add_to_names(left)
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
549 # All lists accounted for - done
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
550 break
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
551 # If not list concatenation
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
552 else:
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
553 break
8218
7c09585bd960 Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8208
diff changeset
554 super().__init__(name, source)
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
555
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
556
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
557 class Scope(dict):
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
558 importStarred = False # set to True when import * is found
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
559
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
560 def __repr__(self):
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
561 scope_cls = self.__class__.__name__
9376
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
562 return f'<{scope_cls} at 0x{id(self):x} {dict.__repr__(self)}>'
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
563
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
564
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
565 class ClassScope(Scope):
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
566 pass
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
567
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
568
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
569 class FunctionScope(Scope):
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
570 """
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
571 I represent a name scope for a function.
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
572
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
573 @ivar globals: Names declared 'global' in this function.
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
574 """
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
575 usesLocals = False
6353
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
576 alwaysUsed = {'__tracebackhide__', '__traceback_info__',
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
577 '__traceback_supplement__'}
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
578
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
579 def __init__(self):
8218
7c09585bd960 Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8208
diff changeset
580 super().__init__()
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
581 # Simplify: manage the special locals as globals
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
582 self.globals = self.alwaysUsed.copy()
3544
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
583 self.returnValue = None # First non-empty return
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
584
9593
89f885d857e4 Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9376
diff changeset
585 def unused_assignments(self):
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
586 """
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
587 Return a generator for the assignments which have not been used.
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
588 """
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
589 for name, binding in self.items():
6742
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
590 if (not binding.used and
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
591 name != '_' and # see issue #202
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
592 name not in self.globals and
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
593 not self.usesLocals and
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
594 isinstance(binding, Assignment)):
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
595 yield name, binding
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
596
9593
89f885d857e4 Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9376
diff changeset
597 def unused_annotations(self):
89f885d857e4 Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9376
diff changeset
598 """
89f885d857e4 Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9376
diff changeset
599 Return a generator for the annotations which have not been used.
89f885d857e4 Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9376
diff changeset
600 """
89f885d857e4 Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9376
diff changeset
601 for name, binding in self.items():
89f885d857e4 Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9376
diff changeset
602 if not binding.used and isinstance(binding, Annotation):
89f885d857e4 Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9376
diff changeset
603 yield name, binding
89f885d857e4 Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9376
diff changeset
604
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
605
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
606 class GeneratorScope(Scope):
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
607 pass
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
608
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
609
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
610 class ModuleScope(Scope):
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
611 """Scope for a module."""
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
612 _futures_allowed = True
6742
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
613 _annotations_future_enabled = False
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
614
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
615
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
616 class DoctestScope(ModuleScope):
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
617 """Scope for a doctest."""
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
618
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
619
8208
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
620 class DetectClassScopedMagic:
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
621 names = dir()
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
622
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
623
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
624 # Globally defined names which are not attributes of the builtins module, or
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
625 # are only present on some platforms.
9376
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
626 _MAGIC_GLOBALS = ['__file__', '__builtins__', '__annotations__', 'WindowsError']
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
627
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
628
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
629 def getNodeName(node):
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
630 # Returns node.id, or node.name, or None
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
631 if hasattr(node, 'id'): # One of the many nodes with an id
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
632 return node.id
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
633 if hasattr(node, 'name'): # an ExceptHandler node
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
634 return node.name
8682
04e80d1aaebf Updated pyflakes to 2.4.0 and pycodestyle to 2.8.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 8312
diff changeset
635 if hasattr(node, 'rest'): # a MatchMapping node
04e80d1aaebf Updated pyflakes to 2.4.0 and pycodestyle to 2.8.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 8312
diff changeset
636 return node.rest
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
637
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
638
7617
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
639 TYPING_MODULES = frozenset(('typing', 'typing_extensions'))
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
640
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
641
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
642 def _is_typing_helper(node, is_name_match_fn, scope_stack):
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
643 """
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
644 Internal helper to determine whether or not something is a member of a
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
645 typing module. This is used as part of working out whether we are within a
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
646 type annotation context.
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
647
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
648 Note: you probably don't want to use this function directly. Instead see the
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
649 utils below which wrap it (`_is_typing` and `_is_any_typing_member`).
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
650 """
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
651
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
652 def _bare_name_is_attr(name):
7064
1010f737def2 pyflakes: upgraded to version 2.1.1 plus repository changes to fix some issues (until 2019-07-09).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7060
diff changeset
653 for scope in reversed(scope_stack):
1010f737def2 pyflakes: upgraded to version 2.1.1 plus repository changes to fix some issues (until 2019-07-09).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7060
diff changeset
654 if name in scope:
1010f737def2 pyflakes: upgraded to version 2.1.1 plus repository changes to fix some issues (until 2019-07-09).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7060
diff changeset
655 return (
1010f737def2 pyflakes: upgraded to version 2.1.1 plus repository changes to fix some issues (until 2019-07-09).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7060
diff changeset
656 isinstance(scope[name], ImportationFrom) and
7617
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
657 scope[name].module in TYPING_MODULES and
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
658 is_name_match_fn(scope[name].real_name)
7064
1010f737def2 pyflakes: upgraded to version 2.1.1 plus repository changes to fix some issues (until 2019-07-09).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7060
diff changeset
659 )
7395
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
660
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
661 return False
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
662
8682
04e80d1aaebf Updated pyflakes to 2.4.0 and pycodestyle to 2.8.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 8312
diff changeset
663 def _module_scope_is_typing(name):
04e80d1aaebf Updated pyflakes to 2.4.0 and pycodestyle to 2.8.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 8312
diff changeset
664 for scope in reversed(scope_stack):
04e80d1aaebf Updated pyflakes to 2.4.0 and pycodestyle to 2.8.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 8312
diff changeset
665 if name in scope:
04e80d1aaebf Updated pyflakes to 2.4.0 and pycodestyle to 2.8.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 8312
diff changeset
666 return (
04e80d1aaebf Updated pyflakes to 2.4.0 and pycodestyle to 2.8.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 8312
diff changeset
667 isinstance(scope[name], Importation) and
04e80d1aaebf Updated pyflakes to 2.4.0 and pycodestyle to 2.8.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 8312
diff changeset
668 scope[name].fullName in TYPING_MODULES
04e80d1aaebf Updated pyflakes to 2.4.0 and pycodestyle to 2.8.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 8312
diff changeset
669 )
04e80d1aaebf Updated pyflakes to 2.4.0 and pycodestyle to 2.8.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 8312
diff changeset
670
04e80d1aaebf Updated pyflakes to 2.4.0 and pycodestyle to 2.8.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 8312
diff changeset
671 return False
04e80d1aaebf Updated pyflakes to 2.4.0 and pycodestyle to 2.8.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 8312
diff changeset
672
7617
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
673 return (
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
674 (
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
675 isinstance(node, ast.Name) and
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
676 _bare_name_is_attr(node.id)
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
677 ) or (
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
678 isinstance(node, ast.Attribute) and
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
679 isinstance(node.value, ast.Name) and
8682
04e80d1aaebf Updated pyflakes to 2.4.0 and pycodestyle to 2.8.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 8312
diff changeset
680 _module_scope_is_typing(node.value.id) and
7617
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
681 is_name_match_fn(node.attr)
6742
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
682 )
7617
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
683 )
6742
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
684
7617
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
685
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
686 def _is_typing(node, typing_attr, scope_stack):
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
687 """
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
688 Determine whether `node` represents the member of a typing module specified
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
689 by `typing_attr`.
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
690
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
691 This is used as part of working out whether we are within a type annotation
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
692 context.
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
693 """
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
694 return _is_typing_helper(node, lambda x: x == typing_attr, scope_stack)
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
695
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
696
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
697 def _is_any_typing_member(node, scope_stack):
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
698 """
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
699 Determine whether `node` represents any member of a typing module.
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
700
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
701 This is used as part of working out whether we are within a type annotation
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
702 context.
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
703 """
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
704 return _is_typing_helper(node, lambda x: True, scope_stack)
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
705
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
706
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
707 def is_typing_overload(value, scope_stack):
6742
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
708 return (
9376
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
709 isinstance(value.source, (ast.FunctionDef, ast.AsyncFunctionDef)) and
7064
1010f737def2 pyflakes: upgraded to version 2.1.1 plus repository changes to fix some issues (until 2019-07-09).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7060
diff changeset
710 any(
7617
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
711 _is_typing(dec, 'overload', scope_stack)
7064
1010f737def2 pyflakes: upgraded to version 2.1.1 plus repository changes to fix some issues (until 2019-07-09).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7060
diff changeset
712 for dec in value.source.decorator_list
1010f737def2 pyflakes: upgraded to version 2.1.1 plus repository changes to fix some issues (until 2019-07-09).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7060
diff changeset
713 )
6742
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
714 )
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
715
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
716
8208
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
717 class AnnotationState:
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
718 NONE = 0
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
719 STRING = 1
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
720 BARE = 2
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
721
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
722
7617
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
723 def in_annotation(func):
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
724 @functools.wraps(func)
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
725 def in_annotation_func(self, *args, **kwargs):
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
726 with self._enter_annotation():
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
727 return func(self, *args, **kwargs)
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
728 return in_annotation_func
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
729
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
730
8208
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
731 def in_string_annotation(func):
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
732 @functools.wraps(func)
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
733 def in_annotation_func(self, *args, **kwargs):
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
734 with self._enter_annotation(AnnotationState.STRING):
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
735 return func(self, *args, **kwargs)
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
736 return in_annotation_func
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
737
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
738
9376
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
739 class Checker:
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
740 """
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
741 I check the cleanliness and sanity of Python code.
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
742
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
743 @ivar _deferredFunctions: Tracking list used by L{deferFunction}. Elements
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
744 of the list are two-tuples. The first element is the callable passed
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
745 to L{deferFunction}. The second element is a copy of the scope stack
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
746 at the time L{deferFunction} was called.
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
747
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
748 @ivar _deferredAssignments: Similar to C{_deferredFunctions}, but for
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
749 callables which are deferred assignment checks.
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
750 """
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
751
6742
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
752 _ast_node_scope = {
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
753 ast.Module: ModuleScope,
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
754 ast.ClassDef: ClassScope,
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
755 ast.FunctionDef: FunctionScope,
9376
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
756 ast.AsyncFunctionDef: FunctionScope,
6742
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
757 ast.Lambda: FunctionScope,
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
758 ast.ListComp: GeneratorScope,
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
759 ast.SetComp: GeneratorScope,
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
760 ast.GeneratorExp: GeneratorScope,
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
761 ast.DictComp: GeneratorScope,
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
762 }
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
763
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
764 nodeDepth = 0
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
765 offset = None
8208
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
766 _in_annotation = AnnotationState.NONE
7617
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
767 _in_deferred = False
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
768
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
769 builtIns = set(builtin_vars).union(_MAGIC_GLOBALS)
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
770 _customBuiltIns = os.environ.get('PYFLAKES_BUILTINS')
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
771 if _customBuiltIns:
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
772 builtIns.update(_customBuiltIns.split(','))
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
773 del _customBuiltIns
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
774
3544
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
775 def __init__(self, tree, filename='(none)', builtins=None,
6742
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
776 withDoctest='PYFLAKES_DOCTEST' in os.environ, file_tokens=()):
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
777 self._nodeHandlers = {}
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
778 self._deferredFunctions = []
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
779 self._deferredAssignments = []
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
780 self.deadScopes = []
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
781 self.messages = []
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
782 self.filename = filename
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
783 if builtins:
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
784 self.builtIns = self.builtIns.union(builtins)
3544
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
785 self.withDoctest = withDoctest
6742
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
786 try:
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
787 self.scopeStack = [Checker._ast_node_scope[type(tree)]()]
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
788 except KeyError:
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
789 raise RuntimeError('No scope implemented for the node %r' % tree)
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
790 self.exceptHandlers = [()]
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
791 self.root = tree
6742
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
792 for builtin in self.builtIns:
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
793 self.addBinding(None, Builtin(builtin))
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
794 self.handleChildren(tree)
7617
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
795 self._in_deferred = True
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
796 self.runDeferred(self._deferredFunctions)
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
797 # Set _deferredFunctions to None so that deferFunction will fail
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
798 # noisily if called after we've run through the deferred functions.
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
799 self._deferredFunctions = None
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
800 self.runDeferred(self._deferredAssignments)
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
801 # Set _deferredAssignments to None so that deferAssignment will fail
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
802 # noisily if called after we've run through the deferred assignments.
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
803 self._deferredAssignments = None
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
804 del self.scopeStack[1:]
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
805 self.popScope()
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
806 self.checkDeadScopes()
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
807
9593
89f885d857e4 Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9376
diff changeset
808 if file_tokens:
89f885d857e4 Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9376
diff changeset
809 warnings.warn(
89f885d857e4 Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9376
diff changeset
810 '`file_tokens` will be removed in a future version',
89f885d857e4 Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9376
diff changeset
811 stacklevel=2,
89f885d857e4 Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9376
diff changeset
812 )
89f885d857e4 Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9376
diff changeset
813
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
814 def deferFunction(self, callable):
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
815 """
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
816 Schedule a function handler to be called just before completion.
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
817
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
818 This is used for handling function bodies, which must be deferred
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
819 because code later in the file might modify the global scope. When
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
820 `callable` is called, the scope at the time this is called will be
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
821 restored, however it will contain any new bindings added to it.
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
822 """
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
823 self._deferredFunctions.append((callable, self.scopeStack[:], self.offset))
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
824
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
825 def deferAssignment(self, callable):
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
826 """
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
827 Schedule an assignment handler to be called just after deferred
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
828 function handlers.
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
829 """
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
830 self._deferredAssignments.append((callable, self.scopeStack[:], self.offset))
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
831
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
832 def runDeferred(self, deferred):
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
833 """
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
834 Run the callables in C{deferred} using their associated scope stack.
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
835 """
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
836 for handler, scope, offset in deferred:
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
837 self.scopeStack = scope
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
838 self.offset = offset
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
839 handler()
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
840
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
841 def _in_doctest(self):
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
842 return (len(self.scopeStack) >= 2 and
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
843 isinstance(self.scopeStack[1], DoctestScope))
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
844
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
845 @property
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
846 def futuresAllowed(self):
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
847 if not all(isinstance(scope, ModuleScope)
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
848 for scope in self.scopeStack):
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
849 return False
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
850
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
851 return self.scope._futures_allowed
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
852
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
853 @futuresAllowed.setter
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
854 def futuresAllowed(self, value):
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
855 assert value is False
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
856 if isinstance(self.scope, ModuleScope):
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
857 self.scope._futures_allowed = False
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
858
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
859 @property
6742
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
860 def annotationsFutureEnabled(self):
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
861 scope = self.scopeStack[0]
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
862 if not isinstance(scope, ModuleScope):
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
863 return False
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
864 return scope._annotations_future_enabled
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
865
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
866 @annotationsFutureEnabled.setter
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
867 def annotationsFutureEnabled(self, value):
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
868 assert value is True
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
869 assert isinstance(self.scope, ModuleScope)
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
870 self.scope._annotations_future_enabled = True
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
871
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
872 @property
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
873 def scope(self):
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
874 return self.scopeStack[-1]
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
875
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
876 def popScope(self):
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
877 self.deadScopes.append(self.scopeStack.pop())
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
878
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
879 def checkDeadScopes(self):
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
880 """
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
881 Look at scopes which have been fully examined and report names in them
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
882 which were imported but unused.
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
883 """
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
884 for scope in self.deadScopes:
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
885 # imports in classes are public members
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
886 if isinstance(scope, ClassScope):
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
887 continue
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
888
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
889 all_binding = scope.get('__all__')
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
890 if all_binding and not isinstance(all_binding, ExportBinding):
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
891 all_binding = None
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
892
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
893 if all_binding:
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
894 all_names = set(all_binding.names)
8208
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
895 undefined = [
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
896 name for name in all_binding.names
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
897 if name not in scope
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
898 ]
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
899 else:
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
900 all_names = undefined = []
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
901
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
902 if undefined:
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
903 if not scope.importStarred and \
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
904 os.path.basename(self.filename) != '__init__.py':
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
905 # Look for possible mistakes in the export list
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
906 for name in undefined:
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
907 self.report(messages.UndefinedExport,
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
908 scope['__all__'].source, name)
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
909
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
910 # mark all import '*' as used by the undefined in __all__
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
911 if scope.importStarred:
6742
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
912 from_list = []
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
913 for binding in scope.values():
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
914 if isinstance(binding, StarImportation):
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
915 binding.used = all_binding
6742
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
916 from_list.append(binding.fullName)
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
917 # report * usage, with a list of possible sources
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
918 from_list = ', '.join(sorted(from_list))
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
919 for name in undefined:
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
920 self.report(messages.ImportStarUsage,
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
921 scope['__all__'].source, name, from_list)
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
922
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
923 # Look for imported names that aren't used.
3544
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
924 for value in scope.values():
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
925 if isinstance(value, Importation):
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
926 used = value.used or value.name in all_names
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
927 if not used:
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
928 messg = messages.UnusedImport
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
929 self.report(messg, value.source, str(value))
3544
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
930 for node in value.redefined:
6742
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
931 if isinstance(self.getParent(node), FOR_TYPES):
3544
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
932 messg = messages.ImportShadowedByLoopVar
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
933 elif used:
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
934 continue
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
935 else:
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
936 messg = messages.RedefinedWhileUnused
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
937 self.report(messg, node, value.name, value.source)
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
938
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
939 def pushScope(self, scopeClass=FunctionScope):
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
940 self.scopeStack.append(scopeClass())
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
941
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
942 def report(self, messageClass, *args, **kwargs):
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
943 self.messages.append(messageClass(self.filename, *args, **kwargs))
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
944
3544
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
945 def getParent(self, node):
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
946 # Lookup the first parent which is not Tuple, List or Starred
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
947 while True:
7395
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
948 node = node._pyflakes_parent
3544
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
949 if not hasattr(node, 'elts') and not hasattr(node, 'ctx'):
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
950 return node
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
951
3544
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
952 def getCommonAncestor(self, lnode, rnode, stop):
7395
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
953 if (
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
954 stop in (lnode, rnode) or
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
955 not (
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
956 hasattr(lnode, '_pyflakes_parent') and
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
957 hasattr(rnode, '_pyflakes_parent')
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
958 )
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
959 ):
3544
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
960 return None
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
961 if lnode is rnode:
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
962 return lnode
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
963
7395
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
964 if (lnode._pyflakes_depth > rnode._pyflakes_depth):
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
965 return self.getCommonAncestor(lnode._pyflakes_parent, rnode, stop)
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
966 if (lnode._pyflakes_depth < rnode._pyflakes_depth):
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
967 return self.getCommonAncestor(lnode, rnode._pyflakes_parent, stop)
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
968 return self.getCommonAncestor(
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
969 lnode._pyflakes_parent,
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
970 rnode._pyflakes_parent,
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
971 stop,
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
972 )
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
973
3544
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
974 def descendantOf(self, node, ancestors, stop):
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
975 for a in ancestors:
3544
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
976 if self.getCommonAncestor(node, a, stop):
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
977 return True
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
978 return False
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
979
6742
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
980 def _getAncestor(self, node, ancestor_type):
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
981 parent = node
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
982 while True:
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
983 if parent is self.root:
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
984 return None
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
985 parent = self.getParent(parent)
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
986 if isinstance(parent, ancestor_type):
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
987 return parent
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
988
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
989 def getScopeNode(self, node):
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
990 return self._getAncestor(node, tuple(Checker._ast_node_scope.keys()))
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
991
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
992 def differentForks(self, lnode, rnode):
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
993 """True, if lnode and rnode are located on different forks of IF/TRY"""
3544
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
994 ancestor = self.getCommonAncestor(lnode, rnode, self.root)
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
995 parts = getAlternatives(ancestor)
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
996 if parts:
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
997 for items in parts:
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
998 if self.descendantOf(lnode, items, ancestor) ^ \
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
999 self.descendantOf(rnode, items, ancestor):
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1000 return True
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1001 return False
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1002
3544
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
1003 def addBinding(self, node, value):
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1004 """
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1005 Called when a binding is altered.
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1006
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1007 - `node` is the statement responsible for the change
3544
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
1008 - `value` is the new value, a Binding instance
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1009 """
7395
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1010 # assert value.source in (node, node._pyflakes_parent):
3544
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
1011 for scope in self.scopeStack[::-1]:
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
1012 if value.name in scope:
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
1013 break
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
1014 existing = scope.get(value.name)
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
1015
6742
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
1016 if (existing and not isinstance(existing, Builtin) and
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
1017 not self.differentForks(node, existing.source)):
3544
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
1018
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
1019 parent_stmt = self.getParent(value.source)
6742
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
1020 if isinstance(existing, Importation) and isinstance(parent_stmt, FOR_TYPES):
3544
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
1021 self.report(messages.ImportShadowedByLoopVar,
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
1022 node, value.name, existing.source)
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
1023
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
1024 elif scope is self.scope:
9376
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1025 if (
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1026 (not existing.used and value.redefines(existing)) and
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1027 (value.name != '_' or isinstance(existing, Importation)) and
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1028 not is_typing_overload(existing, self.scopeStack)
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1029 ):
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1030 self.report(messages.RedefinedWhileUnused,
3544
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
1031 node, value.name, existing.source)
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1032
3544
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
1033 elif isinstance(existing, Importation) and value.redefines(existing):
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
1034 existing.redefined.append(node)
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1035
4502
76f2b46437a6 Updated to pyflakes 1.0.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4465
diff changeset
1036 if value.name in self.scope:
76f2b46437a6 Updated to pyflakes 1.0.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4465
diff changeset
1037 # then assume the rebound name is used as a global or within a loop
76f2b46437a6 Updated to pyflakes 1.0.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4465
diff changeset
1038 value.used = self.scope[value.name].used
76f2b46437a6 Updated to pyflakes 1.0.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4465
diff changeset
1039
8208
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1040 # don't treat annotations as assignments if there is an existing value
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1041 # in scope
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1042 if value.name not in self.scope or not isinstance(value, Annotation):
9376
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1043 cur_scope_pos = -1
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1044 # As per PEP 572, use scope in which outermost generator is defined
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1045 while (
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1046 isinstance(value, NamedExprAssignment) and
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1047 isinstance(self.scopeStack[cur_scope_pos], GeneratorScope)
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1048 ):
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1049 cur_scope_pos -= 1
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1050 self.scopeStack[cur_scope_pos][value.name] = value
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1051
7617
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1052 def _unknown_handler(self, node):
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1053 # this environment variable configures whether to error on unknown
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1054 # ast types.
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1055 #
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1056 # this is silent by default but the error is enabled for the pyflakes
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1057 # testsuite.
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1058 #
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1059 # this allows new syntax to be added to python without *requiring*
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1060 # changes from the pyflakes side. but will still produce an error
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1061 # in the pyflakes testsuite (so more specific handling can be added if
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1062 # needed).
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1063 if os.environ.get('PYFLAKES_ERROR_UNKNOWN'):
9376
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1064 raise NotImplementedError(f'Unexpected type: {type(node)}')
7617
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1065 else:
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1066 self.handleChildren(node)
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1067
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
1068 def getNodeHandler(self, node_class):
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
1069 try:
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
1070 return self._nodeHandlers[node_class]
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
1071 except KeyError:
9376
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1072 nodeType = node_class.__name__.upper()
7617
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1073 self._nodeHandlers[node_class] = handler = getattr(
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1074 self, nodeType, self._unknown_handler,
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1075 )
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
1076 return handler
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
1077
9593
89f885d857e4 Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9376
diff changeset
1078 def handleNodeLoad(self, node, parent):
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1079 name = getNodeName(node)
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1080 if not name:
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1081 return
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1082
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1083 in_generators = None
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1084 importStarred = None
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
1085
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
1086 # try enclosing function scopes and global scope
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1087 for scope in self.scopeStack[-1::-1]:
6353
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
1088 if isinstance(scope, ClassScope):
9376
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1089 if name == '__class__':
6353
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
1090 return
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
1091 elif in_generators is False:
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
1092 # only generators used in a class scope can access the
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
1093 # names of the class. this is skipped during the first
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
1094 # iteration
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
1095 continue
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1096
8208
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1097 binding = scope.get(name, None)
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1098 if isinstance(binding, Annotation) and not self._in_postponed_annotation:
9593
89f885d857e4 Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9376
diff changeset
1099 scope[name].used = True
8208
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1100 continue
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1101
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1102 if name == 'print' and isinstance(binding, Builtin):
6742
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
1103 if (isinstance(parent, ast.BinOp) and
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
1104 isinstance(parent.op, ast.RShift)):
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
1105 self.report(messages.InvalidPrintSyntax, node)
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
1106
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1107 try:
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
1108 scope[name].used = (self.scope, node)
6742
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
1109
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
1110 # if the name of SubImportation is same as
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
1111 # alias of other Importation and the alias
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
1112 # is used, SubImportation also should be marked as used.
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
1113 n = scope[name]
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
1114 if isinstance(n, Importation) and n._has_alias():
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
1115 try:
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
1116 scope[n.fullName].used = (self.scope, node)
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
1117 except KeyError:
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
1118 pass
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1119 except KeyError:
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1120 pass
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1121 else:
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1122 return
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1123
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1124 importStarred = importStarred or scope.importStarred
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1125
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1126 if in_generators is not False:
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1127 in_generators = isinstance(scope, GeneratorScope)
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1128
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1129 if importStarred:
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1130 from_list = []
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1131
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1132 for scope in self.scopeStack[-1::-1]:
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1133 for binding in scope.values():
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1134 if isinstance(binding, StarImportation):
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1135 # mark '*' imports as used for each scope
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1136 binding.used = (self.scope, node)
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1137 from_list.append(binding.fullName)
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1138
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1139 # report * usage, with a list of possible sources
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1140 from_list = ', '.join(sorted(from_list))
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1141 self.report(messages.ImportStarUsage, node, name, from_list)
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1142 return
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1143
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
1144 if name == '__path__' and os.path.basename(self.filename) == '__init__.py':
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
1145 # the special name __path__ is valid only in packages
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
1146 return
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
1147
8208
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1148 if name in DetectClassScopedMagic.names and isinstance(self.scope, ClassScope):
6742
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
1149 return
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
1150
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
1151 # protected with a NameError handler?
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
1152 if 'NameError' not in self.exceptHandlers[-1]:
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
1153 self.report(messages.UndefinedName, node, name)
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1154
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1155 def handleNodeStore(self, node):
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1156 name = getNodeName(node)
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1157 if not name:
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1158 return
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1159 # if the name hasn't already been defined in the current scope
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1160 if isinstance(self.scope, FunctionScope) and name not in self.scope:
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1161 # for each function or module scope above us
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1162 for scope in self.scopeStack[:-1]:
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1163 if not isinstance(scope, (FunctionScope, ModuleScope)):
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1164 continue
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1165 # if the name was defined in that scope, and the name has
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1166 # been accessed already in the current scope, and hasn't
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1167 # been declared global
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
1168 used = name in scope and scope[name].used
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
1169 if used and used[0] is self.scope and name not in self.scope.globals:
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1170 # then it's probably a mistake
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1171 self.report(messages.UndefinedLocal,
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
1172 scope[name].used[1], name, scope[name].source)
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1173 break
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1174
3544
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
1175 parent_stmt = self.getParent(node)
9376
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1176 if isinstance(parent_stmt, ast.AnnAssign) and parent_stmt.value is None:
8208
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1177 binding = Annotation(name, node)
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1178 elif isinstance(parent_stmt, (FOR_TYPES, ast.comprehension)) or (
7395
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1179 parent_stmt != node._pyflakes_parent and
3544
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
1180 not self.isLiteralTupleUnpacking(parent_stmt)):
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1181 binding = Binding(name, node)
9376
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1182 elif (
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1183 name == '__all__' and
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1184 isinstance(self.scope, ModuleScope) and
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1185 isinstance(
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1186 node._pyflakes_parent,
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1187 (ast.Assign, ast.AugAssign, ast.AnnAssign)
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1188 )
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1189 ):
7395
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1190 binding = ExportBinding(name, node._pyflakes_parent, self.scope)
9376
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1191 elif PY38_PLUS and isinstance(parent_stmt, ast.NamedExpr):
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1192 binding = NamedExprAssignment(name, node)
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1193 else:
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1194 binding = Assignment(name, node)
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1195 self.addBinding(node, binding)
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1196
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1197 def handleNodeDelete(self, node):
4502
76f2b46437a6 Updated to pyflakes 1.0.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4465
diff changeset
1198
76f2b46437a6 Updated to pyflakes 1.0.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4465
diff changeset
1199 def on_conditional_branch():
76f2b46437a6 Updated to pyflakes 1.0.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4465
diff changeset
1200 """
76f2b46437a6 Updated to pyflakes 1.0.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4465
diff changeset
1201 Return `True` if node is part of a conditional body.
76f2b46437a6 Updated to pyflakes 1.0.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4465
diff changeset
1202 """
7395
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1203 current = getattr(node, '_pyflakes_parent', None)
4502
76f2b46437a6 Updated to pyflakes 1.0.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4465
diff changeset
1204 while current:
76f2b46437a6 Updated to pyflakes 1.0.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4465
diff changeset
1205 if isinstance(current, (ast.If, ast.While, ast.IfExp)):
76f2b46437a6 Updated to pyflakes 1.0.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4465
diff changeset
1206 return True
7395
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1207 current = getattr(current, '_pyflakes_parent', None)
4502
76f2b46437a6 Updated to pyflakes 1.0.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4465
diff changeset
1208 return False
76f2b46437a6 Updated to pyflakes 1.0.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4465
diff changeset
1209
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1210 name = getNodeName(node)
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1211 if not name:
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1212 return
4502
76f2b46437a6 Updated to pyflakes 1.0.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4465
diff changeset
1213
76f2b46437a6 Updated to pyflakes 1.0.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4465
diff changeset
1214 if on_conditional_branch():
5510
cdcd0cd34e79 Upgraded pyflakes to version 1.5.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 5389
diff changeset
1215 # We cannot predict if this conditional branch is going to
4502
76f2b46437a6 Updated to pyflakes 1.0.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4465
diff changeset
1216 # be executed.
76f2b46437a6 Updated to pyflakes 1.0.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4465
diff changeset
1217 return
76f2b46437a6 Updated to pyflakes 1.0.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4465
diff changeset
1218
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1219 if isinstance(self.scope, FunctionScope) and name in self.scope.globals:
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
1220 self.scope.globals.remove(name)
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1221 else:
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
1222 try:
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
1223 del self.scope[name]
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
1224 except KeyError:
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
1225 self.report(messages.UndefinedName, node, name)
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1226
7617
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1227 @contextlib.contextmanager
8208
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1228 def _enter_annotation(self, ann_type=AnnotationState.BARE):
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1229 orig, self._in_annotation = self._in_annotation, ann_type
7617
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1230 try:
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1231 yield
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1232 finally:
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1233 self._in_annotation = orig
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1234
8208
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1235 @property
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1236 def _in_postponed_annotation(self):
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1237 return (
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1238 self._in_annotation == AnnotationState.STRING or
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1239 self.annotationsFutureEnabled
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1240 )
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1241
3544
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
1242 def handleChildren(self, tree, omit=None):
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
1243 for node in iter_child_nodes(tree, omit=omit):
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1244 self.handleNode(node, tree)
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1245
3544
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
1246 def isLiteralTupleUnpacking(self, node):
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
1247 if isinstance(node, ast.Assign):
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
1248 for child in node.targets + [node.value]:
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
1249 if not hasattr(child, 'elts'):
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
1250 return False
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
1251 return True
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
1252
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1253 def isDocstring(self, node):
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1254 """
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1255 Determine if the given node is a docstring, as long as it is at the
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1256 correct place in the node tree.
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1257 """
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1258 return isinstance(node, ast.Str) or (isinstance(node, ast.Expr) and
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1259 isinstance(node.value, ast.Str))
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1260
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
1261 def getDocstring(self, node):
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
1262 if isinstance(node, ast.Expr):
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
1263 node = node.value
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
1264 if not isinstance(node, ast.Str):
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
1265 return (None, None)
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1266
6742
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
1267 if PYPY or PY38_PLUS:
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1268 doctest_lineno = node.lineno - 1
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1269 else:
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1270 # Computed incorrectly if the docstring has backslash
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1271 doctest_lineno = node.lineno - node.s.count('\n') - 1
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1272
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
1273 return (node.s, doctest_lineno)
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
1274
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1275 def handleNode(self, node, parent):
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1276 if node is None:
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1277 return
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
1278 if self.offset and getattr(node, 'lineno', None) is not None:
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
1279 node.lineno += self.offset[0]
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
1280 node.col_offset += self.offset[1]
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1281 if self.futuresAllowed and not (isinstance(node, ast.ImportFrom) or
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1282 self.isDocstring(node)):
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1283 self.futuresAllowed = False
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
1284 self.nodeDepth += 1
7395
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1285 node._pyflakes_depth = self.nodeDepth
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1286 node._pyflakes_parent = parent
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1287 try:
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
1288 handler = self.getNodeHandler(node.__class__)
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1289 handler(node)
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1290 finally:
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1291 self.nodeDepth -= 1
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1292
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
1293 _getDoctestExamples = doctest.DocTestParser().get_examples
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
1294
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
1295 def handleDoctests(self, node):
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
1296 try:
9376
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1297 (docstring, node_lineno) = self.getDocstring(node.body[0])
3544
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
1298 examples = docstring and self._getDoctestExamples(docstring)
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
1299 except (ValueError, IndexError):
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
1300 # e.g. line 6 of the docstring for <string> has inconsistent
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
1301 # leading whitespace: ...
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
1302 return
3544
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
1303 if not examples:
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
1304 return
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1305
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1306 # Place doctest in module scope
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1307 saved_stack = self.scopeStack
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1308 self.scopeStack = [self.scopeStack[0]]
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
1309 node_offset = self.offset or (0, 0)
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1310 self.pushScope(DoctestScope)
7060
d04e8965af91 checker.py: added a fix taken from pyflakes (2019-07-09)
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
1311 if '_' not in self.scopeStack[0]:
d04e8965af91 checker.py: added a fix taken from pyflakes (2019-07-09)
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
1312 self.addBinding(None, Builtin('_'))
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
1313 for example in examples:
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
1314 try:
6742
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
1315 tree = ast.parse(example.source, "<doctest>")
9376
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1316 except SyntaxError as e:
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
1317 position = (node_lineno + example.lineno + e.lineno,
3544
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
1318 example.indent + 4 + (e.offset or 0))
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
1319 self.report(messages.DoctestSyntaxError, node, position)
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
1320 else:
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
1321 self.offset = (node_offset[0] + node_lineno + example.lineno,
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
1322 node_offset[1] + example.indent + 4)
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
1323 self.handleChildren(tree)
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
1324 self.offset = node_offset
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
1325 self.popScope()
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1326 self.scopeStack = saved_stack
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
1327
8208
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1328 @in_string_annotation
6742
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
1329 def handleStringAnnotation(self, s, node, ref_lineno, ref_col_offset, err):
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
1330 try:
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
1331 tree = ast.parse(s)
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
1332 except SyntaxError:
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
1333 self.report(err, node, s)
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
1334 return
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
1335
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
1336 body = tree.body
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
1337 if len(body) != 1 or not isinstance(body[0], ast.Expr):
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
1338 self.report(err, node, s)
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
1339 return
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
1340
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
1341 parsed_annotation = tree.body[0].value
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
1342 for descendant in ast.walk(parsed_annotation):
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
1343 if (
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
1344 'lineno' in descendant._attributes and
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
1345 'col_offset' in descendant._attributes
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
1346 ):
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
1347 descendant.lineno = ref_lineno
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
1348 descendant.col_offset = ref_col_offset
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
1349
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
1350 self.handleNode(parsed_annotation, node)
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
1351
7617
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1352 @in_annotation
6353
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
1353 def handleAnnotation(self, annotation, node):
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
1354 if isinstance(annotation, ast.Str):
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
1355 # Defer handling forward annotation.
6742
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
1356 self.deferFunction(functools.partial(
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
1357 self.handleStringAnnotation,
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
1358 annotation.s,
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
1359 node,
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
1360 annotation.lineno,
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
1361 annotation.col_offset,
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
1362 messages.ForwardAnnotationSyntaxError,
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
1363 ))
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
1364 elif self.annotationsFutureEnabled:
7617
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1365 fn = in_annotation(Checker.handleNode)
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1366 self.deferFunction(lambda: fn(self, annotation, node))
6353
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
1367 else:
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
1368 self.handleNode(annotation, node)
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
1369
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1370 def ignore(self, node):
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1371 pass
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1372
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1373 # "stmt" type nodes
9376
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1374 DELETE = FOR = ASYNCFOR = WHILE = WITH = WITHITEM = ASYNCWITH = \
4502
76f2b46437a6 Updated to pyflakes 1.0.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4465
diff changeset
1375 EXPR = ASSIGN = handleChildren
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1376
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1377 PASS = ignore
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1378
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1379 # "expr" type nodes
9376
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1380 BOOLOP = UNARYOP = SET = ATTRIBUTE = STARRED = NAMECONSTANT = \
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1381 NAMEDEXPR = handleChildren
7395
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1382
7617
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1383 def SUBSCRIPT(self, node):
8208
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1384 if _is_name_or_attr(node.value, 'Literal'):
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1385 with self._enter_annotation(AnnotationState.NONE):
7617
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1386 self.handleChildren(node)
8208
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1387 elif _is_name_or_attr(node.value, 'Annotated'):
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1388 self.handleNode(node.value, node)
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1389
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1390 # py39+
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1391 if isinstance(node.slice, ast.Tuple):
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1392 slice_tuple = node.slice
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1393 # <py39
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1394 elif (
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1395 isinstance(node.slice, ast.Index) and
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1396 isinstance(node.slice.value, ast.Tuple)
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1397 ):
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1398 slice_tuple = node.slice.value
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1399 else:
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1400 slice_tuple = None
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1401
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1402 # not a multi-arg `Annotated`
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1403 if slice_tuple is None or len(slice_tuple.elts) < 2:
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1404 self.handleNode(node.slice, node)
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1405 else:
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1406 # the first argument is the type
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1407 self.handleNode(slice_tuple.elts[0], node)
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1408 # the rest of the arguments are not
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1409 with self._enter_annotation(AnnotationState.NONE):
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1410 for arg in slice_tuple.elts[1:]:
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1411 self.handleNode(arg, node)
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1412
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1413 self.handleNode(node.ctx, node)
7617
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1414 else:
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1415 if _is_any_typing_member(node.value, self.scopeStack):
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1416 with self._enter_annotation():
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1417 self.handleChildren(node)
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1418 else:
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1419 self.handleChildren(node)
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1420
7395
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1421 def _handle_string_dot_format(self, node):
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1422 try:
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1423 placeholders = tuple(parse_format_string(node.func.value.s))
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1424 except ValueError as e:
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1425 self.report(messages.StringDotFormatInvalidFormat, node, e)
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1426 return
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1427
9376
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1428 auto = None
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1429 next_auto = 0
7395
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1430
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1431 placeholder_positional = set()
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1432 placeholder_named = set()
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1433
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1434 def _add_key(fmtkey):
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1435 """Returns True if there is an error which should early-exit"""
9376
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1436 nonlocal auto, next_auto
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1437
7395
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1438 if fmtkey is None: # end of string or `{` / `}` escapes
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1439 return False
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1440
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1441 # attributes / indices are allowed in `.format(...)`
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1442 fmtkey, _, _ = fmtkey.partition('.')
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1443 fmtkey, _, _ = fmtkey.partition('[')
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1444
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1445 try:
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1446 fmtkey = int(fmtkey)
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1447 except ValueError:
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1448 pass
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1449 else: # fmtkey was an integer
9376
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1450 if auto is True:
7395
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1451 self.report(messages.StringDotFormatMixingAutomatic, node)
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1452 return True
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1453 else:
9376
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1454 auto = False
7395
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1455
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1456 if fmtkey == '':
9376
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1457 if auto is False:
7395
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1458 self.report(messages.StringDotFormatMixingAutomatic, node)
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1459 return True
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1460 else:
9376
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1461 auto = True
7395
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1462
9376
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1463 fmtkey = next_auto
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1464 next_auto += 1
7395
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1465
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1466 if isinstance(fmtkey, int):
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1467 placeholder_positional.add(fmtkey)
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1468 else:
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1469 placeholder_named.add(fmtkey)
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1470
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1471 return False
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1472
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1473 for _, fmtkey, spec, _ in placeholders:
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1474 if _add_key(fmtkey):
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1475 return
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1476
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1477 # spec can also contain format specifiers
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1478 if spec is not None:
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1479 try:
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1480 spec_placeholders = tuple(parse_format_string(spec))
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1481 except ValueError as e:
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1482 self.report(messages.StringDotFormatInvalidFormat, node, e)
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1483 return
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1484
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1485 for _, spec_fmtkey, spec_spec, _ in spec_placeholders:
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1486 # can't recurse again
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1487 if spec_spec is not None and '{' in spec_spec:
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1488 self.report(
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1489 messages.StringDotFormatInvalidFormat,
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1490 node,
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1491 'Max string recursion exceeded',
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1492 )
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1493 return
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1494 if _add_key(spec_fmtkey):
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1495 return
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1496
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1497 # bail early if there is *args or **kwargs
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1498 if (
9376
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1499 # *args
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1500 any(isinstance(arg, ast.Starred) for arg in node.args) or
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1501 # **kwargs
7395
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1502 any(kwd.arg is None for kwd in node.keywords)
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1503 ):
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1504 return
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1505
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1506 substitution_positional = set(range(len(node.args)))
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1507 substitution_named = {kwd.arg for kwd in node.keywords}
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1508
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1509 extra_positional = substitution_positional - placeholder_positional
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1510 extra_named = substitution_named - placeholder_named
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1511
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1512 missing_arguments = (
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1513 (placeholder_positional | placeholder_named) -
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1514 (substitution_positional | substitution_named)
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1515 )
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1516
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1517 if extra_positional:
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1518 self.report(
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1519 messages.StringDotFormatExtraPositionalArguments,
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1520 node,
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1521 ', '.join(sorted(str(x) for x in extra_positional)),
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1522 )
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1523 if extra_named:
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1524 self.report(
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1525 messages.StringDotFormatExtraNamedArguments,
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1526 node,
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1527 ', '.join(sorted(extra_named)),
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1528 )
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1529 if missing_arguments:
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1530 self.report(
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1531 messages.StringDotFormatMissingArgument,
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1532 node,
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1533 ', '.join(sorted(str(x) for x in missing_arguments)),
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1534 )
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1535
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1536 def CALL(self, node):
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1537 if (
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1538 isinstance(node.func, ast.Attribute) and
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1539 isinstance(node.func.value, ast.Str) and
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1540 node.func.attr == 'format'
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1541 ):
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1542 self._handle_string_dot_format(node)
7617
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1543
8208
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1544 omit = []
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1545 annotated = []
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1546 not_annotated = []
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1547
7617
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1548 if (
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1549 _is_typing(node.func, 'cast', self.scopeStack) and
8208
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1550 len(node.args) >= 1
7617
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1551 ):
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1552 with self._enter_annotation():
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1553 self.handleNode(node.args[0], node)
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1554
8208
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1555 elif _is_typing(node.func, 'TypeVar', self.scopeStack):
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1556
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1557 # TypeVar("T", "int", "str")
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1558 omit += ["args"]
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1559 annotated += [arg for arg in node.args[1:]]
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1560
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1561 # TypeVar("T", bound="str")
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1562 omit += ["keywords"]
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1563 annotated += [k.value for k in node.keywords if k.arg == "bound"]
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1564 not_annotated += [
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1565 (k, ["value"] if k.arg == "bound" else None)
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1566 for k in node.keywords
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1567 ]
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1568
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1569 elif _is_typing(node.func, "TypedDict", self.scopeStack):
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1570 # TypedDict("a", {"a": int})
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1571 if len(node.args) > 1 and isinstance(node.args[1], ast.Dict):
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1572 omit += ["args"]
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1573 annotated += node.args[1].values
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1574 not_annotated += [
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1575 (arg, ["values"] if i == 1 else None)
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1576 for i, arg in enumerate(node.args)
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1577 ]
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1578
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1579 # TypedDict("a", a=int)
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1580 omit += ["keywords"]
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1581 annotated += [k.value for k in node.keywords]
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1582 not_annotated += [(k, ["value"]) for k in node.keywords]
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1583
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1584 elif _is_typing(node.func, "NamedTuple", self.scopeStack):
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1585 # NamedTuple("a", [("a", int)])
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1586 if (
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1587 len(node.args) > 1 and
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1588 isinstance(node.args[1], (ast.Tuple, ast.List)) and
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1589 all(isinstance(x, (ast.Tuple, ast.List)) and
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1590 len(x.elts) == 2 for x in node.args[1].elts)
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1591 ):
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1592 omit += ["args"]
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1593 annotated += [elt.elts[1] for elt in node.args[1].elts]
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1594 not_annotated += [(elt.elts[0], None) for elt in node.args[1].elts]
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1595 not_annotated += [
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1596 (arg, ["elts"] if i == 1 else None)
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1597 for i, arg in enumerate(node.args)
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1598 ]
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1599 not_annotated += [(elt, "elts") for elt in node.args[1].elts]
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1600
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1601 # NamedTuple("a", a=int)
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1602 omit += ["keywords"]
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1603 annotated += [k.value for k in node.keywords]
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1604 not_annotated += [(k, ["value"]) for k in node.keywords]
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1605
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1606 if omit:
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1607 with self._enter_annotation(AnnotationState.NONE):
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1608 for na_node, na_omit in not_annotated:
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1609 self.handleChildren(na_node, omit=na_omit)
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1610 self.handleChildren(node, omit=omit)
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1611
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1612 with self._enter_annotation():
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1613 for annotated_node in annotated:
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1614 self.handleNode(annotated_node, node)
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1615 else:
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1616 self.handleChildren(node)
7395
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1617
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1618 def _handle_percent_format(self, node):
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1619 try:
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1620 placeholders = parse_percent_format(node.left.s)
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1621 except ValueError:
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1622 self.report(
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1623 messages.PercentFormatInvalidFormat,
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1624 node,
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1625 'incomplete format',
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1626 )
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1627 return
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1628
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1629 named = set()
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1630 positional_count = 0
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1631 positional = None
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1632 for _, placeholder in placeholders:
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1633 if placeholder is None:
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1634 continue
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1635 name, _, width, precision, conversion = placeholder
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1636
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1637 if conversion == '%':
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1638 continue
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1639
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1640 if conversion not in VALID_CONVERSIONS:
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1641 self.report(
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1642 messages.PercentFormatUnsupportedFormatCharacter,
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1643 node,
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1644 conversion,
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1645 )
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1646
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1647 if positional is None and conversion:
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1648 positional = name is None
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1649
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1650 for part in (width, precision):
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1651 if part is not None and '*' in part:
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1652 if not positional:
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1653 self.report(
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1654 messages.PercentFormatStarRequiresSequence,
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1655 node,
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1656 )
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1657 else:
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1658 positional_count += 1
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1659
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1660 if positional and name is not None:
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1661 self.report(
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1662 messages.PercentFormatMixedPositionalAndNamed,
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1663 node,
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1664 )
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1665 return
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1666 elif not positional and name is None:
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1667 self.report(
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1668 messages.PercentFormatMixedPositionalAndNamed,
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1669 node,
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1670 )
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1671 return
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1672
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1673 if positional:
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1674 positional_count += 1
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1675 else:
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1676 named.add(name)
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1677
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1678 if (
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1679 isinstance(node.right, (ast.List, ast.Tuple)) and
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1680 # does not have any *splats (py35+ feature)
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1681 not any(
9376
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1682 isinstance(elt, ast.Starred)
7395
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1683 for elt in node.right.elts
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1684 )
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1685 ):
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1686 substitution_count = len(node.right.elts)
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1687 if positional and positional_count != substitution_count:
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1688 self.report(
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1689 messages.PercentFormatPositionalCountMismatch,
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1690 node,
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1691 positional_count,
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1692 substitution_count,
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1693 )
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1694 elif not positional:
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1695 self.report(messages.PercentFormatExpectedMapping, node)
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1696
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1697 if (
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1698 isinstance(node.right, ast.Dict) and
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1699 all(isinstance(k, ast.Str) for k in node.right.keys)
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1700 ):
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1701 if positional and positional_count > 1:
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1702 self.report(messages.PercentFormatExpectedSequence, node)
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1703 return
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1704
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1705 substitution_keys = {k.s for k in node.right.keys}
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1706 extra_keys = substitution_keys - named
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1707 missing_keys = named - substitution_keys
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1708 if not positional and extra_keys:
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1709 self.report(
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1710 messages.PercentFormatExtraNamedArguments,
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1711 node,
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1712 ', '.join(sorted(extra_keys)),
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1713 )
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1714 if not positional and missing_keys:
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1715 self.report(
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1716 messages.PercentFormatMissingArgument,
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1717 node,
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1718 ', '.join(sorted(missing_keys)),
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1719 )
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1720
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1721 def BINOP(self, node):
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1722 if (
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1723 isinstance(node.op, ast.Mod) and
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1724 isinstance(node.left, ast.Str)
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1725 ):
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1726 self._handle_percent_format(node)
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1727 self.handleChildren(node)
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1728
7617
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1729 def STR(self, node):
8208
37836fa8e4ea Updated pyflakes to 2.3.1 and pycodestyle to 2.7.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7960
diff changeset
1730 if self._in_annotation:
7617
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1731 fn = functools.partial(
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1732 self.handleStringAnnotation,
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1733 node.s,
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1734 node,
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1735 node.lineno,
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1736 node.col_offset,
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1737 messages.ForwardAnnotationSyntaxError,
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1738 )
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1739 if self._in_deferred:
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1740 fn()
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1741 else:
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1742 self.deferFunction(fn)
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1743
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1744 if PY38_PLUS:
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1745 def CONSTANT(self, node):
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1746 if isinstance(node.value, str):
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1747 return self.STR(node)
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1748 else:
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1749 NUM = BYTES = ELLIPSIS = CONSTANT = ignore
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1750
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1751 # "slice" type nodes
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1752 SLICE = EXTSLICE = INDEX = handleChildren
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1753
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1754 # expression contexts are node instances too, though being constants
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1755 LOAD = STORE = DEL = AUGLOAD = AUGSTORE = PARAM = ignore
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1756
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1757 # same for operators
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1758 AND = OR = ADD = SUB = MULT = DIV = MOD = POW = LSHIFT = RSHIFT = \
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1759 BITOR = BITXOR = BITAND = FLOORDIV = INVERT = NOT = UADD = USUB = \
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1760 EQ = NOTEQ = LT = LTE = GT = GTE = IS = ISNOT = IN = NOTIN = \
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1761 MATMULT = ignore
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1762
6353
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
1763 def RAISE(self, node):
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
1764 self.handleChildren(node)
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
1765
9376
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1766 arg = node.exc
6353
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
1767
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
1768 if isinstance(arg, ast.Call):
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
1769 if is_notimplemented_name_node(arg.func):
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
1770 # Handle "raise NotImplemented(...)"
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
1771 self.report(messages.RaiseNotImplemented, node)
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
1772 elif is_notimplemented_name_node(arg):
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
1773 # Handle "raise NotImplemented"
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
1774 self.report(messages.RaiseNotImplemented, node)
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
1775
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1776 # additional node types
7395
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1777 COMPREHENSION = KEYWORD = FORMATTEDVALUE = handleChildren
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1778
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1779 _in_fstring = False
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1780
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1781 def JOINEDSTR(self, node):
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1782 if (
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1783 # the conversion / etc. flags are parsed as f-strings without
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1784 # placeholders
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1785 not self._in_fstring and
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1786 not any(isinstance(x, ast.FormattedValue) for x in node.values)
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1787 ):
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1788 self.report(messages.FStringMissingPlaceholders, node)
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1789
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1790 self._in_fstring, orig = True, self._in_fstring
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1791 try:
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1792 self.handleChildren(node)
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1793 finally:
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1794 self._in_fstring = orig
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1795
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1796 def DICT(self, node):
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1797 # Complain if there are duplicate keys with different values
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1798 # If they have the same value it's not going to cause potentially
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1799 # unexpected behaviour so we'll not complain.
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1800 keys = [
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1801 convert_to_value(key) for key in node.keys
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1802 ]
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1803
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1804 key_counts = counter(keys)
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1805 duplicate_keys = [
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1806 key for key, count in key_counts.items()
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1807 if count > 1
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1808 ]
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1809
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1810 for key in duplicate_keys:
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1811 key_indices = [i for i, i_key in enumerate(keys) if i_key == key]
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1812
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1813 values = counter(
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1814 convert_to_value(node.values[index])
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1815 for index in key_indices
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1816 )
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1817 if any(count == 1 for value, count in values.items()):
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1818 for key_index in key_indices:
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1819 key_node = node.keys[key_index]
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1820 if isinstance(key, VariableKey):
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1821 self.report(messages.MultiValueRepeatedKeyVariable,
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1822 key_node,
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1823 key.name)
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1824 else:
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1825 self.report(
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1826 messages.MultiValueRepeatedKeyLiteral,
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1827 key_node,
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1828 key,
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1829 )
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1830 self.handleChildren(node)
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1831
7617
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1832 def IF(self, node):
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1833 if isinstance(node.test, ast.Tuple) and node.test.elts != []:
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1834 self.report(messages.IfTuple, node)
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1835 self.handleChildren(node)
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1836
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1837 IFEXP = IF
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1838
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1839 def ASSERT(self, node):
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1840 if isinstance(node.test, ast.Tuple) and node.test.elts != []:
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1841 self.report(messages.AssertTuple, node)
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1842 self.handleChildren(node)
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1843
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1844 def GLOBAL(self, node):
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1845 """
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1846 Keep track of globals declarations.
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1847 """
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1848 global_scope_index = 1 if self._in_doctest() else 0
4502
76f2b46437a6 Updated to pyflakes 1.0.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4465
diff changeset
1849 global_scope = self.scopeStack[global_scope_index]
76f2b46437a6 Updated to pyflakes 1.0.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4465
diff changeset
1850
76f2b46437a6 Updated to pyflakes 1.0.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4465
diff changeset
1851 # Ignore 'global' statement in global scope.
76f2b46437a6 Updated to pyflakes 1.0.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4465
diff changeset
1852 if self.scope is not global_scope:
76f2b46437a6 Updated to pyflakes 1.0.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4465
diff changeset
1853
76f2b46437a6 Updated to pyflakes 1.0.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4465
diff changeset
1854 # One 'global' statement can bind multiple (comma-delimited) names.
76f2b46437a6 Updated to pyflakes 1.0.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4465
diff changeset
1855 for node_name in node.names:
76f2b46437a6 Updated to pyflakes 1.0.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4465
diff changeset
1856 node_value = Assignment(node_name, node)
76f2b46437a6 Updated to pyflakes 1.0.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4465
diff changeset
1857
76f2b46437a6 Updated to pyflakes 1.0.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4465
diff changeset
1858 # Remove UndefinedName messages already reported for this name.
7064
1010f737def2 pyflakes: upgraded to version 2.1.1 plus repository changes to fix some issues (until 2019-07-09).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7060
diff changeset
1859 # TODO: if the global is not used in this scope, it does not
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1860 # become a globally defined name. See test_unused_global.
4502
76f2b46437a6 Updated to pyflakes 1.0.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4465
diff changeset
1861 self.messages = [
76f2b46437a6 Updated to pyflakes 1.0.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4465
diff changeset
1862 m for m in self.messages if not
5065
39f27a2a2ea3 Little fix in the pyflakes checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
1863 isinstance(m, messages.UndefinedName) or
39f27a2a2ea3 Little fix in the pyflakes checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
1864 m.message_args[0] != node_name]
4502
76f2b46437a6 Updated to pyflakes 1.0.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4465
diff changeset
1865
76f2b46437a6 Updated to pyflakes 1.0.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4465
diff changeset
1866 # Bind name to global scope if it doesn't exist already.
76f2b46437a6 Updated to pyflakes 1.0.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4465
diff changeset
1867 global_scope.setdefault(node_name, node_value)
76f2b46437a6 Updated to pyflakes 1.0.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4465
diff changeset
1868
76f2b46437a6 Updated to pyflakes 1.0.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4465
diff changeset
1869 # Bind name to non-global scopes, but as already "used".
76f2b46437a6 Updated to pyflakes 1.0.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4465
diff changeset
1870 node_value.used = (global_scope, node)
76f2b46437a6 Updated to pyflakes 1.0.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4465
diff changeset
1871 for scope in self.scopeStack[global_scope_index + 1:]:
76f2b46437a6 Updated to pyflakes 1.0.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4465
diff changeset
1872 scope[node_name] = node_value
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1873
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1874 NONLOCAL = GLOBAL
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1875
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
1876 def GENERATOREXP(self, node):
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
1877 self.pushScope(GeneratorScope)
3544
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
1878 self.handleChildren(node)
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
1879 self.popScope()
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1880
9376
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1881 LISTCOMP = DICTCOMP = SETCOMP = GENERATOREXP
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1882
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1883 def NAME(self, node):
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1884 """
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1885 Handle occurrence of Name (which can be a load/store/delete access.)
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1886 """
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1887 # Locate the name in locals / function / globals scopes.
7617
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1888 if isinstance(node.ctx, ast.Load):
9593
89f885d857e4 Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9376
diff changeset
1889 self.handleNodeLoad(node, self.getParent(node))
6742
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
1890 if (node.id == 'locals' and isinstance(self.scope, FunctionScope) and
7395
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1891 isinstance(node._pyflakes_parent, ast.Call)):
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
1892 # we are doing locals() call in current scope
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
1893 self.scope.usesLocals = True
7617
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1894 elif isinstance(node.ctx, ast.Store):
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
1895 self.handleNodeStore(node)
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1896 elif isinstance(node.ctx, ast.Del):
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1897 self.handleNodeDelete(node)
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1898 else:
6742
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
1899 # Unknown context
9376
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1900 raise RuntimeError(f"Got impossible expression context: {node.ctx!r}")
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1901
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1902 def CONTINUE(self, node):
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1903 # Walk the tree up until we see a loop (OK), a function or class
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1904 # definition (not OK), for 'continue', a finally block (not OK), or
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1905 # the top module scope (not OK)
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1906 n = node
7395
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1907 while hasattr(n, '_pyflakes_parent'):
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1908 n, n_child = n._pyflakes_parent, n
9376
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1909 if isinstance(n, (ast.While, ast.For, ast.AsyncFor)):
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1910 # Doesn't apply unless it's in the loop itself
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1911 if n_child not in n.orelse:
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1912 return
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1913 if isinstance(n, (ast.FunctionDef, ast.ClassDef)):
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1914 break
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1915 # Handle Try/TryFinally difference in Python < and >= 3.3
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1916 if hasattr(n, 'finalbody') and isinstance(node, ast.Continue):
7395
dd50d0f4c588 pyflakes: updated to repository as of 2020-02-03.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
1917 if n_child in n.finalbody and not PY38_PLUS:
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1918 self.report(messages.ContinueInFinally, node)
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1919 return
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1920 if isinstance(node, ast.Continue):
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1921 self.report(messages.ContinueOutsideLoop, node)
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1922 else: # ast.Break
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1923 self.report(messages.BreakOutsideLoop, node)
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1924
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1925 BREAK = CONTINUE
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1926
3544
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
1927 def RETURN(self, node):
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1928 if isinstance(self.scope, (ClassScope, ModuleScope)):
4502
76f2b46437a6 Updated to pyflakes 1.0.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4465
diff changeset
1929 self.report(messages.ReturnOutsideFunction, node)
76f2b46437a6 Updated to pyflakes 1.0.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4465
diff changeset
1930 return
76f2b46437a6 Updated to pyflakes 1.0.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4465
diff changeset
1931
3889
9357550095a1 Fixed an issue in the pyflakes checker module (taken from Github).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3670
diff changeset
1932 if (
9357550095a1 Fixed an issue in the pyflakes checker module (taken from Github).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3670
diff changeset
1933 node.value and
9357550095a1 Fixed an issue in the pyflakes checker module (taken from Github).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3670
diff changeset
1934 hasattr(self.scope, 'returnValue') and
9357550095a1 Fixed an issue in the pyflakes checker module (taken from Github).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3670
diff changeset
1935 not self.scope.returnValue
9357550095a1 Fixed an issue in the pyflakes checker module (taken from Github).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3670
diff changeset
1936 ):
3544
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
1937 self.scope.returnValue = node.value
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
1938 self.handleNode(node.value, node)
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
1939
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
1940 def YIELD(self, node):
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1941 if isinstance(self.scope, (ClassScope, ModuleScope)):
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1942 self.report(messages.YieldOutsideFunction, node)
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1943 return
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1944
3544
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
1945 self.handleNode(node.value, node)
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
1946
4502
76f2b46437a6 Updated to pyflakes 1.0.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4465
diff changeset
1947 AWAIT = YIELDFROM = YIELD
3544
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
1948
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1949 def FUNCTIONDEF(self, node):
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1950 for deco in node.decorator_list:
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1951 self.handleNode(deco, node)
3544
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
1952 self.LAMBDA(node)
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1953 self.addBinding(node, FunctionDefinition(node.name, node))
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1954 # doctest does not process doctest within a doctest,
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1955 # or in nested functions.
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1956 if (self.withDoctest and
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1957 not self._in_doctest() and
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
1958 not isinstance(self.scope, FunctionScope)):
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
1959 self.deferFunction(lambda: self.handleDoctests(node))
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1960
4465
2fbb5bdb8ddf Prepared eric for Python 3.5 to support the new 'async def' function definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
1961 ASYNCFUNCTIONDEF = FUNCTIONDEF
2fbb5bdb8ddf Prepared eric for Python 3.5 to support the new 'async def' function definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
1962
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1963 def LAMBDA(self, node):
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1964 args = []
3544
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
1965 annotations = []
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1966
9376
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1967 if PY38_PLUS:
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1968 for arg in node.args.posonlyargs:
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1969 args.append(arg.arg)
3544
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
1970 annotations.append(arg.annotation)
9376
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1971 for arg in node.args.args + node.args.kwonlyargs:
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1972 args.append(arg.arg)
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1973 annotations.append(arg.annotation)
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1974 defaults = node.args.defaults + node.args.kw_defaults
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1975
9376
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1976 has_annotations = not isinstance(node, ast.Lambda)
3544
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
1977
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
1978 for arg_name in ('vararg', 'kwarg'):
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
1979 wildcard = getattr(node.args, arg_name)
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1980 if not wildcard:
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1981 continue
9376
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1982 args.append(wildcard.arg)
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1983 if has_annotations:
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1984 annotations.append(wildcard.annotation)
3544
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
1985
9376
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
1986 if has_annotations:
3544
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
1987 annotations.append(node.returns)
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
1988
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
1989 if len(set(args)) < len(args):
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
1990 for (idx, arg) in enumerate(args):
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
1991 if arg in args[:idx]:
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
1992 self.report(messages.DuplicateArgument, node, arg)
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
1993
6353
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
1994 for annotation in annotations:
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
1995 self.handleAnnotation(annotation, node)
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
1996
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
1997 for default in defaults:
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
1998 self.handleNode(default, node)
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1999
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
2000 def runFunction():
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
2001
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
2002 self.pushScope()
6742
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
2003
7064
1010f737def2 pyflakes: upgraded to version 2.1.1 plus repository changes to fix some issues (until 2019-07-09).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7060
diff changeset
2004 self.handleChildren(node, omit=['decorator_list', 'returns'])
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
2005
9593
89f885d857e4 Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9376
diff changeset
2006 def check_unused_assignments():
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
2007 """
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
2008 Check to see if any assignments have not been used.
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
2009 """
9593
89f885d857e4 Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9376
diff changeset
2010 for name, binding in self.scope.unused_assignments():
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
2011 self.report(messages.UnusedVariable, binding.source, name)
9593
89f885d857e4 Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9376
diff changeset
2012
89f885d857e4 Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9376
diff changeset
2013 def check_unused_annotations():
89f885d857e4 Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9376
diff changeset
2014 """
89f885d857e4 Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9376
diff changeset
2015 Check to see if any annotations have not been used.
89f885d857e4 Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9376
diff changeset
2016 """
89f885d857e4 Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9376
diff changeset
2017 for name, binding in self.scope.unused_annotations():
89f885d857e4 Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9376
diff changeset
2018 self.report(messages.UnusedAnnotation, binding.source, name)
89f885d857e4 Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9376
diff changeset
2019
89f885d857e4 Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9376
diff changeset
2020 self.deferAssignment(check_unused_assignments)
89f885d857e4 Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9376
diff changeset
2021 self.deferAssignment(check_unused_annotations)
3544
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
2022
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
2023 self.popScope()
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
2024
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
2025 self.deferFunction(runFunction)
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
2026
6742
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
2027 def ARGUMENTS(self, node):
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
2028 self.handleChildren(node, omit=('defaults', 'kw_defaults'))
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
2029
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
2030 def ARG(self, node):
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
2031 self.addBinding(node, Argument(node.arg, self.getScopeNode(node)))
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
2032
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
2033 def CLASSDEF(self, node):
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
2034 """
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
2035 Check names used in a class definition, including its decorators, base
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
2036 classes, and the body of its definition. Additionally, add its name to
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
2037 the current scope.
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
2038 """
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
2039 for deco in node.decorator_list:
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
2040 self.handleNode(deco, node)
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
2041 for baseNode in node.bases:
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
2042 self.handleNode(baseNode, node)
9376
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
2043 for keywordNode in node.keywords:
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
2044 self.handleNode(keywordNode, node)
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
2045 self.pushScope(ClassScope)
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
2046 # doctest does not process doctest within a doctest
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
2047 # classes within classes are processed.
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
2048 if (self.withDoctest and
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
2049 not self._in_doctest() and
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
2050 not isinstance(self.scope, FunctionScope)):
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
2051 self.deferFunction(lambda: self.handleDoctests(node))
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
2052 for stmt in node.body:
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
2053 self.handleNode(stmt, node)
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
2054 self.popScope()
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
2055 self.addBinding(node, ClassDefinition(node.name, node))
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
2056
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
2057 def AUGASSIGN(self, node):
9593
89f885d857e4 Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9376
diff changeset
2058 self.handleNodeLoad(node.target, node)
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
2059 self.handleNode(node.value, node)
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
2060 self.handleNode(node.target, node)
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
2061
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
2062 def TUPLE(self, node):
9376
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
2063 if isinstance(node.ctx, ast.Store):
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
2064 # Python 3 advanced tuple unpacking: a, *b, c = d.
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
2065 # Only one starred expression is allowed, and no more than 1<<8
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
2066 # assignments are allowed before a stared expression. There is
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
2067 # also a limit of 1<<24 expressions after the starred expression,
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
2068 # which is impossible to test due to memory restrictions, but we
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
2069 # add it here anyway
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
2070 has_starred = False
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
2071 star_loc = -1
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
2072 for i, n in enumerate(node.elts):
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
2073 if isinstance(n, ast.Starred):
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
2074 if has_starred:
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
2075 self.report(messages.TwoStarredExpressions, node)
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
2076 # The SyntaxError doesn't distinguish two from more
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
2077 # than two.
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
2078 break
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
2079 has_starred = True
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
2080 star_loc = i
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
2081 if star_loc >= 1 << 8 or len(node.elts) - star_loc - 1 >= 1 << 24:
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
2082 self.report(messages.TooManyExpressionsInStarredAssignment, node)
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
2083 self.handleChildren(node)
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
2084
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
2085 LIST = TUPLE
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
2086
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
2087 def IMPORT(self, node):
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
2088 for alias in node.names:
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
2089 if '.' in alias.name and not alias.asname:
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
2090 importation = SubmoduleImportation(alias.name, node)
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
2091 else:
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
2092 name = alias.asname or alias.name
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
2093 importation = Importation(name, node, alias.name)
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
2094 self.addBinding(node, importation)
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
2095
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
2096 def IMPORTFROM(self, node):
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
2097 if node.module == '__future__':
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
2098 if not self.futuresAllowed:
9376
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
2099 self.report(messages.LateFutureImport, node)
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
2100 else:
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
2101 self.futuresAllowed = False
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
2102
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
2103 module = ('.' * node.level) + (node.module or '')
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
2104
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
2105 for alias in node.names:
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
2106 name = alias.asname or alias.name
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
2107 if node.module == '__future__':
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
2108 importation = FutureImportation(name, node, self.scope)
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
2109 if alias.name not in __future__.all_feature_names:
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
2110 self.report(messages.FutureFeatureNotDefined,
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
2111 node, alias.name)
6742
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
2112 if alias.name == 'annotations':
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
2113 self.annotationsFutureEnabled = True
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
2114 elif alias.name == '*':
9376
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
2115 if not isinstance(self.scope, ModuleScope):
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
2116 self.report(messages.ImportStarNotPermitted,
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
2117 node, module)
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
2118 continue
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
2119
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
2120 self.scope.importStarred = True
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
2121 self.report(messages.ImportStarUsed, node, module)
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
2122 importation = StarImportation(module, node)
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
2123 else:
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
2124 importation = ImportationFrom(name, node,
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
2125 module, alias.name)
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
2126 self.addBinding(node, importation)
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
2127
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
2128 def TRY(self, node):
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
2129 handler_names = []
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
2130 # List the exception handlers
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
2131 for i, handler in enumerate(node.handlers):
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
2132 if isinstance(handler.type, ast.Tuple):
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
2133 for exc_type in handler.type.elts:
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
2134 handler_names.append(getNodeName(exc_type))
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
2135 elif handler.type:
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
2136 handler_names.append(getNodeName(handler.type))
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
2137
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
2138 if handler.type is None and i < len(node.handlers) - 1:
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
2139 self.report(messages.DefaultExceptNotLast, handler)
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
2140 # Memorize the except handlers and process the body
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
2141 self.exceptHandlers.append(handler_names)
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
2142 for child in node.body:
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
2143 self.handleNode(child, node)
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
2144 self.exceptHandlers.pop()
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
2145 # Process the other nodes: "except:", "else:", "finally:"
3544
431c842fd09a updated pyflakes to version 0.8.1 (Python 3.4.0 compatible)
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3456
diff changeset
2146 self.handleChildren(node, omit='body')
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
2147
9376
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
2148 TRYSTAR = TRY
3177
5af61402d74d Update pyflakes to 0.7.3
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
2149
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
2150 def EXCEPTHANDLER(self, node):
9376
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
2151 if node.name is None:
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
2152 self.handleChildren(node)
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
2153 return
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
2154
6353
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
2155 # If the name already exists in the scope, modify state of existing
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
2156 # binding.
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
2157 if node.name in self.scope:
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
2158 self.handleNodeStore(node)
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
2159
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
2160 # 3.x: the name of the exception, which is not a Name node, but a
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
2161 # simple string, creates a local that is only bound within the scope of
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
2162 # the except: block. As such, temporarily remove the existing binding
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
2163 # to more accurately determine if the name is used in the except:
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
2164 # block.
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
2165
6742
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
2166 try:
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
2167 prev_definition = self.scope.pop(node.name)
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
2168 except KeyError:
6353
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
2169 prev_definition = None
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
2170
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
2171 self.handleNodeStore(node)
2571
e6bb19eb87ea Fixes for autocodecheck with pyflakes and update of py2flakes to 0.6.1.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
2172 self.handleChildren(node)
6353
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
2173
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
2174 # See discussion on https://github.com/PyCQA/pyflakes/pull/59
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
2175
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
2176 # We're removing the local name since it's being unbound after leaving
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
2177 # the except: block and it's always unbound if the except: block is
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
2178 # never entered. This will cause an "undefined name" error raised if
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
2179 # the checked code tries to use the name afterwards.
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
2180 #
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
2181 # Unless it's been removed already. Then do nothing.
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
2182
6353
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
2183 try:
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
2184 binding = self.scope.pop(node.name)
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
2185 except KeyError:
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
2186 pass
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
2187 else:
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
2188 if not binding.used:
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
2189 self.report(messages.UnusedVariable, node, node.name)
5067
e2f171f08af8 Updated pyflakes to 1.2.3+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5065
diff changeset
2190
6353
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
2191 # Restore.
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
2192 if prev_definition:
6742
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
2193 self.scope[node.name] = prev_definition
4555
861e1741985c Adjustments to future imports for Python 2 compatibility.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 4502
diff changeset
2194
5510
cdcd0cd34e79 Upgraded pyflakes to version 1.5.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 5389
diff changeset
2195 def ANNASSIGN(self, node):
6353
6a0f3abd6878 upgraded pyflakes to version 2.0.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6048
diff changeset
2196 self.handleAnnotation(node.annotation, node)
9376
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
2197 # If the assignment has value, handle the *value* now.
5510
cdcd0cd34e79 Upgraded pyflakes to version 1.5.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 5389
diff changeset
2198 if node.value:
9376
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
2199 # If the annotation is `TypeAlias`, handle the *value* as an annotation.
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
2200 if _is_typing(node.annotation, 'TypeAlias', self.scopeStack):
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
2201 self.handleAnnotation(node.value, node)
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
2202 else:
e143a7e7254b Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
2203 self.handleNode(node.value, node)
9593
89f885d857e4 Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9376
diff changeset
2204 self.handleNode(node.target, node)
5510
cdcd0cd34e79 Upgraded pyflakes to version 1.5.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 5389
diff changeset
2205
6742
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
2206 def COMPARE(self, node):
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
2207 left = node.left
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
2208 for op, right in zip(node.ops, node.comparators):
7617
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
2209 if (
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
2210 isinstance(op, (ast.Is, ast.IsNot)) and (
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
2211 _is_const_non_singleton(left) or
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
2212 _is_const_non_singleton(right)
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
2213 )
a0e162a50ad7 Syntax Checker: updated pyflakes to version 2.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7395
diff changeset
2214 ):
6742
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
2215 self.report(messages.IsLiteral, node)
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
2216 left = right
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
2217
7cb30f7f94f6 Upgraded pyflakes to 2.1.0
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 6645
diff changeset
2218 self.handleChildren(node)
8682
04e80d1aaebf Updated pyflakes to 2.4.0 and pycodestyle to 2.8.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 8312
diff changeset
2219
04e80d1aaebf Updated pyflakes to 2.4.0 and pycodestyle to 2.8.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 8312
diff changeset
2220 MATCH = MATCH_CASE = MATCHCLASS = MATCHOR = MATCHSEQUENCE = handleChildren
04e80d1aaebf Updated pyflakes to 2.4.0 and pycodestyle to 2.8.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 8312
diff changeset
2221 MATCHSINGLETON = MATCHVALUE = handleChildren
04e80d1aaebf Updated pyflakes to 2.4.0 and pycodestyle to 2.8.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 8312
diff changeset
2222
04e80d1aaebf Updated pyflakes to 2.4.0 and pycodestyle to 2.8.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 8312
diff changeset
2223 def _match_target(self, node):
04e80d1aaebf Updated pyflakes to 2.4.0 and pycodestyle to 2.8.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 8312
diff changeset
2224 self.handleNodeStore(node)
04e80d1aaebf Updated pyflakes to 2.4.0 and pycodestyle to 2.8.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 8312
diff changeset
2225 self.handleChildren(node)
04e80d1aaebf Updated pyflakes to 2.4.0 and pycodestyle to 2.8.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 8312
diff changeset
2226
04e80d1aaebf Updated pyflakes to 2.4.0 and pycodestyle to 2.8.0.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 8312
diff changeset
2227 MATCHAS = MATCHMAPPING = MATCHSTAR = _match_target

eric ide

mercurial