Skip to content

Commit 7306c2b

Browse files
committed
Rename to for_annotations
1 parent a30cfcb commit 7306c2b

File tree

2 files changed

+42
-42
lines changed

2 files changed

+42
-42
lines changed

pyflakes/checker.py

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -310,12 +310,12 @@ class Binding(object):
310310
the node that this binding was last used.
311311
"""
312312

313-
def __init__(self, name, source, during_type_checking):
313+
def __init__(self, name, source, for_annotations):
314314
self.name = name
315315
self.source = source
316316
self.used = False
317-
assert isinstance(during_type_checking, bool)
318-
self.during_type_checking = during_type_checking
317+
assert isinstance(for_annotations, bool)
318+
self.for_annotations = for_annotations
319319

320320
def __str__(self):
321321
return self.name
@@ -340,7 +340,7 @@ class Builtin(Definition):
340340
"""A definition created for all Python builtins."""
341341

342342
def __init__(self, name):
343-
super(Builtin, self).__init__(name, None, during_type_checking=False)
343+
super(Builtin, self).__init__(name, None, for_annotations=False)
344344

345345
def __repr__(self):
346346
return '<%s object %r at 0x%x>' % (self.__class__.__name__,
@@ -382,11 +382,11 @@ class Importation(Definition):
382382
@type fullName: C{str}
383383
"""
384384

385-
def __init__(self, name, source, during_type_checking, full_name=None):
385+
def __init__(self, name, source, for_annotations, full_name=None):
386386
self.fullName = full_name or name
387387
self.redefined = []
388388
super(Importation, self).__init__(name, source,
389-
during_type_checking=during_type_checking)
389+
for_annotations=for_annotations)
390390

391391
def redefines(self, other):
392392
if isinstance(other, SubmoduleImportation):
@@ -431,12 +431,12 @@ class SubmoduleImportation(Importation):
431431
name is also the same, to avoid false positives.
432432
"""
433433

434-
def __init__(self, name, source, during_type_checking):
434+
def __init__(self, name, source, for_annotations):
435435
# A dot should only appear in the name when it is a submodule import
436436
assert '.' in name and (not source or isinstance(source, ast.Import))
437437
package_name = name.split('.')[0]
438438
super(SubmoduleImportation, self).__init__(
439-
package_name, source, during_type_checking=during_type_checking)
439+
package_name, source, for_annotations=for_annotations)
440440
self.fullName = name
441441

442442
def redefines(self, other):
@@ -454,7 +454,7 @@ def source_statement(self):
454454

455455
class ImportationFrom(Importation):
456456

457-
def __init__(self, name, source, module, during_type_checking, real_name=None):
457+
def __init__(self, name, source, module, for_annotations, real_name=None):
458458
self.module = module
459459
self.real_name = real_name or name
460460

@@ -464,7 +464,7 @@ def __init__(self, name, source, module, during_type_checking, real_name=None):
464464
full_name = module + '.' + self.real_name
465465

466466
super(ImportationFrom, self).__init__(name, source, full_name=full_name,
467-
during_type_checking=during_type_checking)
467+
for_annotations=for_annotations)
468468

469469
def __str__(self):
470470
"""Return import full name with alias."""
@@ -486,9 +486,9 @@ def source_statement(self):
486486
class StarImportation(Importation):
487487
"""A binding created by a 'from x import *' statement."""
488488

489-
def __init__(self, name, source, during_type_checking):
489+
def __init__(self, name, source, for_annotations):
490490
super(StarImportation, self).__init__('*', source,
491-
during_type_checking=during_type_checking)
491+
for_annotations=for_annotations)
492492
# Each star importation needs a unique name, and
493493
# may not be the module name otherwise it will be deemed imported
494494
self.name = name + '.*'
@@ -515,7 +515,7 @@ class FutureImportation(ImportationFrom):
515515

516516
def __init__(self, name, source, scope):
517517
super(FutureImportation, self).__init__(name, source, '__future__',
518-
during_type_checking=False)
518+
for_annotations=False)
519519
self.used = (scope, source)
520520

521521

@@ -524,7 +524,7 @@ class Argument(Binding):
524524
Represents binding a name as an argument.
525525
"""
526526
def __init__(self, name, source):
527-
super(Argument, self).__init__(name, source, during_type_checking=False)
527+
super(Argument, self).__init__(name, source, for_annotations=False)
528528

529529

530530
class Assignment(Binding):
@@ -560,7 +560,7 @@ class ExportBinding(Binding):
560560
C{__all__} will not have an unused import warning reported for them.
561561
"""
562562

563-
def __init__(self, name, source, scope, during_type_checking):
563+
def __init__(self, name, source, scope, for_annotations):
564564
if '__all__' in scope and isinstance(source, ast.AugAssign):
565565
self.names = list(scope['__all__'].names)
566566
else:
@@ -591,7 +591,7 @@ def _add_to_names(container):
591591
# If not list concatenation
592592
else:
593593
break
594-
super(ExportBinding, self).__init__(name, source, during_type_checking)
594+
super(ExportBinding, self).__init__(name, source, for_annotations)
595595

596596

597597
class Scope(dict):
@@ -1175,7 +1175,7 @@ def handleNodeLoad(self, node):
11751175
scope[n.fullName].used = (self.scope, node)
11761176
except KeyError:
11771177
pass
1178-
if n.during_type_checking and not self._in_annotation:
1178+
if n.for_annotations and not self._in_annotation:
11791179
# Only defined during type-checking; this does not count. Real code
11801180
# (not an annotation) using this binding will not work.
11811181
continue
@@ -1239,14 +1239,14 @@ def handleNodeStore(self, node):
12391239
if isinstance(parent_stmt, (FOR_TYPES, ast.comprehension)) or (
12401240
parent_stmt != node._pyflakes_parent and
12411241
not self.isLiteralTupleUnpacking(parent_stmt)):
1242-
binding = Binding(name, node, during_type_checking=self._in_type_checking)
1242+
binding = Binding(name, node, for_annotations=self._in_type_checking)
12431243
elif name == '__all__' and isinstance(self.scope, ModuleScope):
12441244
binding = ExportBinding(name, node._pyflakes_parent, self.scope,
1245-
during_type_checking=self._in_type_checking)
1245+
for_annotations=self._in_type_checking)
12461246
elif PY2 and isinstance(getattr(node, 'ctx', None), ast.Param):
12471247
binding = Argument(name, self.getScopeNode(node))
12481248
else:
1249-
binding = Assignment(name, node, during_type_checking=self._in_type_checking)
1249+
binding = Assignment(name, node, for_annotations=self._in_type_checking)
12501250
self.addBinding(node, binding)
12511251

12521252
def handleNodeDelete(self, node):
@@ -1875,7 +1875,7 @@ def GLOBAL(self, node):
18751875
# One 'global' statement can bind multiple (comma-delimited) names.
18761876
for node_name in node.names:
18771877
node_value = Assignment(node_name, node,
1878-
during_type_checking=self._in_type_checking)
1878+
for_annotations=self._in_type_checking)
18791879

18801880
# Remove UndefinedName messages already reported for this name.
18811881
# TODO: if the global is not used in this scope, it does not
@@ -1978,7 +1978,7 @@ def FUNCTIONDEF(self, node):
19781978
self.handleNode(deco, node)
19791979
self.LAMBDA(node)
19801980
self.addBinding(node, FunctionDefinition(
1981-
node.name, node, during_type_checking=self._in_type_checking))
1981+
node.name, node, for_annotations=self._in_type_checking))
19821982
# doctest does not process doctest within a doctest,
19831983
# or in nested functions.
19841984
if (self.withDoctest and
@@ -2104,7 +2104,7 @@ def CLASSDEF(self, node):
21042104
self.handleNode(stmt, node)
21052105
self.popScope()
21062106
self.addBinding(node, ClassDefinition(
2107-
node.name, node, during_type_checking=self._in_type_checking))
2107+
node.name, node, for_annotations=self._in_type_checking))
21082108

21092109
def AUGASSIGN(self, node):
21102110
self.handleNodeLoad(node.target)
@@ -2140,11 +2140,11 @@ def IMPORT(self, node):
21402140
for alias in node.names:
21412141
if '.' in alias.name and not alias.asname:
21422142
importation = SubmoduleImportation(
2143-
alias.name, node, during_type_checking=self._in_type_checking)
2143+
alias.name, node, for_annotations=self._in_type_checking)
21442144
else:
21452145
name = alias.asname or alias.name
21462146
importation = Importation(name, node, full_name=alias.name,
2147-
during_type_checking=self._in_type_checking)
2147+
for_annotations=self._in_type_checking)
21482148
self.addBinding(node, importation)
21492149

21502150
def IMPORTFROM(self, node):
@@ -2175,11 +2175,11 @@ def IMPORTFROM(self, node):
21752175
self.scope.importStarred = True
21762176
self.report(messages.ImportStarUsed, node, module)
21772177
importation = StarImportation(
2178-
module, node, during_type_checking=self._in_type_checking)
2178+
module, node, for_annotations=self._in_type_checking)
21792179
else:
21802180
importation = ImportationFrom(
21812181
name, node, module, real_name=alias.name,
2182-
during_type_checking=self._in_type_checking)
2182+
for_annotations=self._in_type_checking)
21832183
self.addBinding(node, importation)
21842184

21852185
def TRY(self, node):

pyflakes/test/test_imports.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,86 +14,86 @@
1414
class TestImportationObject(TestCase):
1515

1616
def test_import_basic(self):
17-
binding = Importation('a', None, during_type_checking=False, full_name='a')
17+
binding = Importation('a', None, for_annotations=False, full_name='a')
1818
assert binding.source_statement == 'import a'
1919
assert str(binding) == 'a'
2020

2121
def test_import_as(self):
22-
binding = Importation('c', None, during_type_checking=False, full_name='a')
22+
binding = Importation('c', None, for_annotations=False, full_name='a')
2323
assert binding.source_statement == 'import a as c'
2424
assert str(binding) == 'a as c'
2525

2626
def test_import_submodule(self):
27-
binding = SubmoduleImportation('a.b', None, during_type_checking=False)
27+
binding = SubmoduleImportation('a.b', None, for_annotations=False)
2828
assert binding.source_statement == 'import a.b'
2929
assert str(binding) == 'a.b'
3030

3131
def test_import_submodule_as(self):
3232
# A submodule import with an as clause is not a SubmoduleImportation
33-
binding = Importation('c', None, during_type_checking=False, full_name='a.b')
33+
binding = Importation('c', None, for_annotations=False, full_name='a.b')
3434
assert binding.source_statement == 'import a.b as c'
3535
assert str(binding) == 'a.b as c'
3636

3737
def test_import_submodule_as_source_name(self):
38-
binding = Importation('a', None, during_type_checking=False, full_name='a.b')
38+
binding = Importation('a', None, for_annotations=False, full_name='a.b')
3939
assert binding.source_statement == 'import a.b as a'
4040
assert str(binding) == 'a.b as a'
4141

4242
def test_importfrom_relative(self):
4343
binding = ImportationFrom('a', None, '.',
44-
during_type_checking=False, real_name='a')
44+
for_annotations=False, real_name='a')
4545
assert binding.source_statement == 'from . import a'
4646
assert str(binding) == '.a'
4747

4848
def test_importfrom_relative_parent(self):
4949
binding = ImportationFrom('a', None, '..',
50-
during_type_checking=False, real_name='a')
50+
for_annotations=False, real_name='a')
5151
assert binding.source_statement == 'from .. import a'
5252
assert str(binding) == '..a'
5353

5454
def test_importfrom_relative_with_module(self):
5555
binding = ImportationFrom('b', None, '..a',
56-
during_type_checking=False, real_name='b')
56+
for_annotations=False, real_name='b')
5757
assert binding.source_statement == 'from ..a import b'
5858
assert str(binding) == '..a.b'
5959

6060
def test_importfrom_relative_with_module_as(self):
6161
binding = ImportationFrom('c', None, '..a',
62-
during_type_checking=False, real_name='b')
62+
for_annotations=False, real_name='b')
6363
assert binding.source_statement == 'from ..a import b as c'
6464
assert str(binding) == '..a.b as c'
6565

6666
def test_importfrom_member(self):
6767
binding = ImportationFrom('b', None, 'a',
68-
during_type_checking=False, real_name='b')
68+
for_annotations=False, real_name='b')
6969
assert binding.source_statement == 'from a import b'
7070
assert str(binding) == 'a.b'
7171

7272
def test_importfrom_submodule_member(self):
7373
binding = ImportationFrom('c', None, 'a.b',
74-
during_type_checking=False, real_name='c')
74+
for_annotations=False, real_name='c')
7575
assert binding.source_statement == 'from a.b import c'
7676
assert str(binding) == 'a.b.c'
7777

7878
def test_importfrom_member_as(self):
7979
binding = ImportationFrom('c', None, 'a',
80-
during_type_checking=False, real_name='b')
80+
for_annotations=False, real_name='b')
8181
assert binding.source_statement == 'from a import b as c'
8282
assert str(binding) == 'a.b as c'
8383

8484
def test_importfrom_submodule_member_as(self):
8585
binding = ImportationFrom('d', None, 'a.b',
86-
during_type_checking=False, real_name='c')
86+
for_annotations=False, real_name='c')
8787
assert binding.source_statement == 'from a.b import c as d'
8888
assert str(binding) == 'a.b.c as d'
8989

9090
def test_importfrom_star(self):
91-
binding = StarImportation('a.b', None, during_type_checking=False)
91+
binding = StarImportation('a.b', None, for_annotations=False)
9292
assert binding.source_statement == 'from a.b import *'
9393
assert str(binding) == 'a.b.*'
9494

9595
def test_importfrom_star_relative(self):
96-
binding = StarImportation('.b', None, during_type_checking=False)
96+
binding = StarImportation('.b', None, for_annotations=False)
9797
assert binding.source_statement == 'from .b import *'
9898
assert str(binding) == '.b.*'
9999

0 commit comments

Comments
 (0)