From c5eb55bd512d9e5ecd2f246c51857c082159e002 Mon Sep 17 00:00:00 2001 From: anthony sottile Date: Tue, 22 Sep 2026 15:52:37 -0400 Subject: [PATCH] allow subtree KeyError to bubble this behaviour was uncovered -- and I think the KeyError is actually more readable than the custom exception: ```pytb >>> Checker(ast.parse('a').body[0].value) Traceback (most recent call last): File "/home/asottile/workspace/pyflakes/pyflakes/checker.py", line 738, in __init__ scope_tp = Checker._ast_node_scope[type(tree)] ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^ KeyError: During handling of the above exception, another exception occurred: Traceback (most recent call last): File "", line 1, in Checker(ast.parse('a').body[0].value) ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/asottile/workspace/pyflakes/pyflakes/checker.py", line 740, in __init__ raise RuntimeError('No scope implemented for the node %r' % tree) RuntimeError: No scope implemented for the node Name(id='a', ctx=Load()) ``` now: ```pytb >>> Checker(ast.parse('a').body[0].value) Traceback (most recent call last): File "", line 1, in Checker(ast.parse('a').body[0].value) ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/asottile/workspace/pyflakes/pyflakes/checker.py", line 737, in __init__ scope_tp = Checker._ast_node_scope[type(tree)] ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^ KeyError: ``` --- pyflakes/checker.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pyflakes/checker.py b/pyflakes/checker.py index 6f7ea548..1bfbbc08 100644 --- a/pyflakes/checker.py +++ b/pyflakes/checker.py @@ -734,10 +734,7 @@ def __init__(self, tree, filename='(none)', builtins=None, self.root = tree self.scopeStack = [] - try: - scope_tp = Checker._ast_node_scope[type(tree)] - except KeyError: - raise RuntimeError('No scope implemented for the node %r' % tree) + scope_tp = Checker._ast_node_scope[type(tree)] with self.in_scope(scope_tp): for builtin in self.builtIns: