diff options
author | Anthony Sottile <asottile@umich.edu> | 2019-11-19 13:58:52 -0800 |
---|---|---|
committer | Anthony Sottile <asottile@umich.edu> | 2019-11-19 13:58:52 -0800 |
commit | 1b5f177731f3487bb0aa6e591ee734886a2d2328 (patch) | |
tree | 89298216c3d3a59cebce147f823c07dc7b282dac | |
parent | 1911c203a13826d2eb03d582d60874b91e36f4fc (diff) | |
download | pyflakes-future_proof.tar.gz |
Make pyflakes more resistant to syntax additionsfuture_proof
-rw-r--r-- | pyflakes/checker.py | 20 | ||||
-rw-r--r-- | tox.ini | 1 |
2 files changed, 20 insertions, 1 deletions
diff --git a/pyflakes/checker.py b/pyflakes/checker.py index c8ccf56..3f5a7e0 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): @@ -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 |