use LocalScope in ScopeVisitor._new_scope to simplify typing

This commit is contained in:
Jimmy Lai 2019-09-27 10:46:20 -07:00 committed by jimmylai
parent 894a0f7424
commit e24ca294b6
2 changed files with 9 additions and 7 deletions

View file

@ -359,14 +359,10 @@ class ScopeVisitor(cst.CSTVisitor):
@contextmanager
def _new_scope(
self, kind: Type[Scope], name: Optional[str] = None
self, kind: Type[LocalScope], name: Optional[str] = None
) -> Iterator[None]:
parent_scope = self.scope
if issubclass(kind, LocalScope):
# pyre-ignore: pyre cannot understand issubclass and complained the extra name arg
self.scope = kind(parent_scope, name)
else:
self.scope = kind(parent_scope)
self.scope = kind(parent_scope, name)
try:
yield
finally:

View file

@ -642,5 +642,11 @@ class ScopeProviderTest(UnitTest):
self.assertEqual(
scope_of_f.get_fully_qualified_names_for(cst.Name(value=builtin)),
{f"builtins.{builtin}"},
f"test builtin: {builtin}",
f"Test builtin: {builtin}.",
)
self.assertEqual(
scope_of_module.get_fully_qualified_names_for(cst.Name(value="d")),
set(),
"Test variable d in global scope.",
)