summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Sottile <asottile@umich.edu>2020-02-07 13:36:12 -0800
committerGitHub <noreply@github.com>2020-02-07 13:36:12 -0800
commit4ed1ba41d1406dbb6c9ffbd369c2f523c2dc48f3 (patch)
tree2abe01fe784bb309c335281d916c1d95cff25b47
parentbe88036019005b769596ca82fb7b82dfdffdca0f (diff)
downloadpyflakes-4ed1ba41d1406dbb6c9ffbd369c2f523c2dc48f3.tar.gz
Make pyflakes more resistant to syntax additions (#490)
-rw-r--r--pyflakes/checker.py20
-rw-r--r--tox.ini1
2 files changed, 20 insertions, 1 deletions
diff --git a/pyflakes/checker.py b/pyflakes/checker.py
index d157008..8a512d4 100644
--- a/pyflakes/checker.py
+++ b/pyflakes/checker.py
@@ -1009,12 +1009,30 @@ class Checker(object):
self.scope[value.name] = value
+ def _unknown_handler(self, node):
+ # this environment variable configures whether to error on unknown
+ # ast types.
+ #
+ # this is silent by default but the error is enabled for the pyflakes
+ # testsuite.
+ #
+ # this allows new syntax to be added to python without *requiring*
+ # changes from the pyflakes side. but will still produce an error
+ # in the pyflakes testsuite (so more specific handling can be added if
+ # needed).
+ if os.environ.get('PYFLAKES_ERROR_UNKNOWN'):
+ raise NotImplementedError('Unexpected type: {}'.format(type(node)))
+ else:
+ self.handleChildren(node)
+
def getNodeHandler(self, node_class):
try:
return self._nodeHandlers[node_class]
except KeyError:
nodeType = getNodeType(node_class)
- self._nodeHandlers[node_class] = handler = getattr(self, nodeType)
+ self._nodeHandlers[node_class] = handler = getattr(
+ self, nodeType, self._unknown_handler,
+ )
return handler
def handleNodeLoad(self, node):
diff --git a/tox.ini b/tox.ini
index 5821483..f2256c8 100644
--- a/tox.ini
+++ b/tox.ini
@@ -5,6 +5,7 @@ envlist =
[testenv]
deps = flake8==3.6.0
+setenv = PYFLAKES_ERROR_UNKNOWN=1
commands =
python -m unittest discover pyflakes
flake8 pyflakes setup.py