Commits

Ronny Pfannschmidt committed 8b50f24

make all of the body block of a try availaible for its else block

  • Participants
  • Parent commits c6cd5fa
  • Branches experimental

Comments (0)

Files changed (2)

File pyflakes/checker.py

             common = set(valid_scopes[0])
             for scope in valid_scopes[1:]:
                 common.intersection_update(scope)
+            # when the body scope doesnt raise,
+            # its currently the best to consider its names
+            # availiable for the orelse part
+            if not body_scope.raises:
+                common.update(body_scope)
+
             for name in common:
                 #XXX: really ok?
                 self.scope[name] = valid_scopes[0].pop(name)
                 for scope in valid_scopes[1:]:
-                    scope.pop(name)
+                    scope.pop(name, None) # might not exist when body is ok
 
 
         for stmt in node.orelse:

File pyflakes/test/test_scopes.py

                   raise ImportError('no elementree implementation found')
         """)
 
+    def test_body_availiable_in_else(self):
+        self.flakes("""
+            try:
+                from lxml import etree
+            except ImportError:
+                print('missing')
+            else:
+                print(etree)
+            """)