Skip to content

Commit be68d83

Browse files
committed
Rename to for_annotations
1 parent 60b44c8 commit be68d83

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
@@ -321,12 +321,12 @@ class Binding(object):
321321
the node that this binding was last used.
322322
"""
323323

324-
def __init__(self, name, source, during_type_checking):
324+
def __init__(self, name, source, for_annotations):
325325
self.name = name
326326
self.source = source
327327
self.used = False
328-
assert isinstance(during_type_checking, bool)
329-
self.during_type_checking = during_type_checking
328+
assert isinstance(for_annotations, bool)
329+
self.for_annotations = for_annotations
330330

331331
def __str__(self):
332332
return self.name
@@ -351,7 +351,7 @@ class Builtin(Definition):
351351
"""A definition created for all Python builtins."""
352352

353353
def __init__(self, name):
354-
super(Builtin, self).__init__(name, None, during_type_checking=False)
354+
super(Builtin, self).__init__(name, None, for_annotations=False)
355355

356356
def __repr__(self):
357357
return '<%s object %r at 0x%x>' % (self.__class__.__name__,
@@ -393,11 +393,11 @@ class Importation(Definition):
393393
@type fullName: C{str}
394394
"""
395395

396-
def __init__(self, name, source, during_type_checking, full_name=None):
396+
def __init__(self, name, source, for_annotations, full_name=None):
397397
self.fullName = full_name or name
398398
self.redefined = []
399399
super(Importation, self).__init__(name, source,
400-
during_type_checking=during_type_checking)
400+
for_annotations=for_annotations)
401401

402402
def redefines(self, other):
403403
if isinstance(other, SubmoduleImportation):
@@ -442,12 +442,12 @@ class SubmoduleImportation(Importation):
442442
name is also the same, to avoid false positives.
443443
"""
444444

445-
def __init__(self, name, source, during_type_checking):
445+
def __init__(self, name, source, for_annotations):
446446
# A dot should only appear in the name when it is a submodule import
447447
assert '.' in name and (not source or isinstance(source, ast.Import))
448448
package_name = name.split('.')[0]
449449
super(SubmoduleImportation, self).__init__(
450-
package_name, source, during_type_checking=during_type_checking)
450+
package_name, source, for_annotations=for_annotations)
451451
self.fullName = name
452452

453453
def redefines(self, other):
@@ -465,7 +465,7 @@ def source_statement(self):
465465

466466
class ImportationFrom(Importation):
467467

468-
def __init__(self, name, source, module, during_type_checking, real_name=None):
468+
def __init__(self, name, source, module, for_annotations, real_name=None):
469469
self.module = module
470470
self.real_name = real_name or name
471471

@@ -475,7 +475,7 @@ def __init__(self, name, source, module, during_type_checking, real_name=None):
475475
full_name = module + '.' + self.real_name
476476

477477
super(ImportationFrom, self).__init__(name, source, full_name=full_name,
478-
during_type_checking=during_type_checking)
478+
for_annotations=for_annotations)
479479

480480
def __str__(self):
481481
"""Return import full name with alias."""
@@ -497,9 +497,9 @@ def source_statement(self):
497497
class StarImportation(Importation):
498498
"""A binding created by a 'from x import *' statement."""
499499

500-
def __init__(self, name, source, during_type_checking):
500+
def __init__(self, name, source, for_annotations):
501501
super(StarImportation, self).__init__('*', source,
502-
during_type_checking=during_type_checking)
502+
for_annotations=for_annotations)
503503
# Each star importation needs a unique name, and
504504
# may not be the module name otherwise it will be deemed imported
505505
self.name = name + '.*'
@@ -526,7 +526,7 @@ class FutureImportation(ImportationFrom):
526526

527527
def __init__(self, name, source, scope):
528528
super(FutureImportation, self).__init__(name, source, '__future__',
529-
during_type_checking=False)
529+
for_annotations=False)
530530
self.used = (scope, source)
531531

532532

@@ -535,7 +535,7 @@ class Argument(Binding):
535535
Represents binding a name as an argument.
536536
"""
537537
def __init__(self, name, source):
538-
super(Argument, self).__init__(name, source, during_type_checking=False)
538+
super(Argument, self).__init__(name, source, for_annotations=False)
539539

540540

541541
class Assignment(Binding):
@@ -585,7 +585,7 @@ class ExportBinding(Binding):
585585
C{__all__} will not have an unused import warning reported for them.
586586
"""
587587

588-
def __init__(self, name, source, scope, during_type_checking):
588+
def __init__(self, name, source, scope, for_annotations):
589589
if '__all__' in scope and isinstance(source, ast.AugAssign):
590590
self.names = list(scope['__all__'].names)
591591
else:
@@ -616,7 +616,7 @@ def _add_to_names(container):
616616
# If not list concatenation
617617
else:
618618
break
619-
super(ExportBinding, self).__init__(name, source, during_type_checking)
619+
super(ExportBinding, self).__init__(name, source, for_annotations)
620620

621621

622622
class Scope(dict):
@@ -1228,7 +1228,7 @@ def handleNodeLoad(self, node):
12281228
scope[n.fullName].used = (self.scope, node)
12291229
except KeyError:
12301230
pass
1231-
if n.during_type_checking and not self._in_annotation:
1231+
if n.for_annotations and not self._in_annotation:
12321232
# Only defined during type-checking; this does not count. Real code
12331233
# (not an annotation) using this binding will not work.
12341234
continue
@@ -1294,14 +1294,14 @@ def handleNodeStore(self, node):
12941294
elif isinstance(parent_stmt, (FOR_TYPES, ast.comprehension)) or (
12951295
parent_stmt != node._pyflakes_parent and
12961296
not self.isLiteralTupleUnpacking(parent_stmt)):
1297-
binding = Binding(name, node, during_type_checking=self._in_type_checking)
1297+
binding = Binding(name, node, for_annotations=self._in_type_checking)
12981298
elif name == '__all__' and isinstance(self.scope, ModuleScope):
12991299
binding = ExportBinding(name, node._pyflakes_parent, self.scope,
1300-
during_type_checking=self._in_type_checking)
1300+
for_annotations=self._in_type_checking)
13011301
elif PY2 and isinstance(getattr(node, 'ctx', None), ast.Param):
13021302
binding = Argument(name, self.getScopeNode(node))
13031303
else:
1304-
binding = Assignment(name, node, during_type_checking=self._in_type_checking)
1304+
binding = Assignment(name, node, for_annotations=self._in_type_checking)
13051305
self.addBinding(node, binding)
13061306

13071307
def handleNodeDelete(self, node):
@@ -2017,7 +2017,7 @@ def GLOBAL(self, node):
20172017
# One 'global' statement can bind multiple (comma-delimited) names.
20182018
for node_name in node.names:
20192019
node_value = Assignment(node_name, node,
2020-
during_type_checking=self._in_type_checking)
2020+
for_annotations=self._in_type_checking)
20212021

20222022
# Remove UndefinedName messages already reported for this name.
20232023
# TODO: if the global is not used in this scope, it does not
@@ -2120,7 +2120,7 @@ def FUNCTIONDEF(self, node):
21202120
self.handleNode(deco, node)
21212121
self.LAMBDA(node)
21222122
self.addBinding(node, FunctionDefinition(
2123-
node.name, node, during_type_checking=self._in_type_checking))
2123+
node.name, node, for_annotations=self._in_type_checking))
21242124
# doctest does not process doctest within a doctest,
21252125
# or in nested functions.
21262126
if (self.withDoctest and
@@ -2246,7 +2246,7 @@ def CLASSDEF(self, node):
22462246
self.handleNode(stmt, node)
22472247
self.popScope()
22482248
self.addBinding(node, ClassDefinition(
2249-
node.name, node, during_type_checking=self._in_type_checking))
2249+
node.name, node, for_annotations=self._in_type_checking))
22502250

22512251
def AUGASSIGN(self, node):
22522252
self.handleNodeLoad(node.target)
@@ -2282,11 +2282,11 @@ def IMPORT(self, node):
22822282
for alias in node.names:
22832283
if '.' in alias.name and not alias.asname:
22842284
importation = SubmoduleImportation(
2285-
alias.name, node, during_type_checking=self._in_type_checking)
2285+
alias.name, node, for_annotations=self._in_type_checking)
22862286
else:
22872287
name = alias.asname or alias.name
22882288
importation = Importation(name, node, full_name=alias.name,
2289-
during_type_checking=self._in_type_checking)
2289+
for_annotations=self._in_type_checking)
22902290
self.addBinding(node, importation)
22912291

22922292
def IMPORTFROM(self, node):
@@ -2317,11 +2317,11 @@ def IMPORTFROM(self, node):
23172317
self.scope.importStarred = True
23182318
self.report(messages.ImportStarUsed, node, module)
23192319
importation = StarImportation(
2320-
module, node, during_type_checking=self._in_type_checking)
2320+
module, node, for_annotations=self._in_type_checking)
23212321
else:
23222322
importation = ImportationFrom(
23232323
name, node, module, real_name=alias.name,
2324-
during_type_checking=self._in_type_checking)
2324+
for_annotations=self._in_type_checking)
23252325
self.addBinding(node, importation)
23262326

23272327
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)