summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Sottile <asottile@umich.edu>2019-01-19 11:52:30 -0800
committerIan Stapleton Cordasco <graffatcolmingov@gmail.com>2019-01-21 08:05:42 -0600
commit14f28ba0279e3547c09b06870f90f01167da08ec (patch)
treeacebb5dd8c6623936edbdda069857f88c5512ce1
parent357a2e3cf3461b414ba5a70485a62c411d557c3f (diff)
downloadpyflakes-14f28ba0279e3547c09b06870f90f01167da08ec.tar.gz
Use file_tokens to better match flake8 api
-rw-r--r--pyflakes/api.py4
-rw-r--r--pyflakes/checker.py10
-rw-r--r--pyflakes/test/harness.py6
-rw-r--r--pyflakes/test/test_undefined_names.py4
4 files changed, 13 insertions, 11 deletions
diff --git a/pyflakes/api.py b/pyflakes/api.py
index 72d6b6c..6226e5d 100644
--- a/pyflakes/api.py
+++ b/pyflakes/api.py
@@ -70,8 +70,8 @@ def check(codeString, filename, reporter=None):
reporter.unexpectedError(filename, 'problem decoding source')
return 1
# Okay, it's syntactically valid. Now check it.
- tokens = checker.make_tokens(codeString)
- w = checker.Checker(tree, tokens=tokens, filename=filename)
+ file_tokens = checker.make_tokens(codeString)
+ w = checker.Checker(tree, file_tokens=file_tokens, filename=filename)
w.messages.sort(key=lambda m: m.lineno)
for warning in w.messages:
reporter.flake(warning)
diff --git a/pyflakes/checker.py b/pyflakes/checker.py
index 480ee00..b8d7be7 100644
--- a/pyflakes/checker.py
+++ b/pyflakes/checker.py
@@ -632,11 +632,11 @@ class Checker(object):
builtIns.update(_customBuiltIns.split(','))
del _customBuiltIns
- # TODO: tokens= is required to perform checks on type comments, eventually
- # make this a required positional argument. For now it is defaulted
- # to `()` for api compatibility.
+ # TODO: file_tokens= is required to perform checks on type comments,
+ # eventually make this a required positional argument. For now it
+ # is defaulted to `()` for api compatibility.
def __init__(self, tree, filename='(none)', builtins=None,
- withDoctest='PYFLAKES_DOCTEST' in os.environ, tokens=()):
+ withDoctest='PYFLAKES_DOCTEST' in os.environ, file_tokens=()):
self._nodeHandlers = {}
self._deferredFunctions = []
self._deferredAssignments = []
@@ -652,7 +652,7 @@ class Checker(object):
raise RuntimeError('No scope implemented for the node %r' % tree)
self.exceptHandlers = [()]
self.root = tree
- self._type_comments = _collect_type_comments(tree, tokens)
+ self._type_comments = _collect_type_comments(tree, file_tokens)
for builtin in self.builtIns:
self.addBinding(None, Builtin(builtin))
self.handleChildren(tree)
diff --git a/pyflakes/test/harness.py b/pyflakes/test/harness.py
index d375ea3..b20ac79 100644
--- a/pyflakes/test/harness.py
+++ b/pyflakes/test/harness.py
@@ -16,11 +16,13 @@ class TestCase(unittest.TestCase):
def flakes(self, input, *expectedOutputs, **kw):
tree = ast.parse(textwrap.dedent(input))
- tokens = checker.make_tokens(textwrap.dedent(input))
+ file_tokens = checker.make_tokens(textwrap.dedent(input))
if kw.get('is_segment'):
tree = tree.body[0]
kw.pop('is_segment')
- w = checker.Checker(tree, tokens=tokens, withDoctest=self.withDoctest, **kw)
+ w = checker.Checker(
+ tree, file_tokens=file_tokens, withDoctest=self.withDoctest, **kw
+ )
outputs = [type(o) for o in w.messages]
expectedOutputs = list(expectedOutputs)
outputs.sort(key=lambda t: t.__name__)
diff --git a/pyflakes/test/test_undefined_names.py b/pyflakes/test/test_undefined_names.py
index 25e28dd..c952cbb 100644
--- a/pyflakes/test/test_undefined_names.py
+++ b/pyflakes/test/test_undefined_names.py
@@ -848,7 +848,7 @@ class NameTests(TestCase):
raised.
"""
tree = ast.parse("x = 10")
- tokens = checker.make_tokens("x = 10")
+ file_tokens = checker.make_tokens("x = 10")
# Make it into something unrecognizable.
tree.body[0].targets[0].ctx = object()
- self.assertRaises(RuntimeError, checker.Checker, tree, tokens=tokens)
+ self.assertRaises(RuntimeError, checker.Checker, tree, file_tokens=file_tokens)