mirror of
https://github.com/Instagram/LibCST.git
synced 2025-12-23 10:35:53 +00:00
use LocalScope in ScopeVisitor._new_scope to simplify typing
This commit is contained in:
parent
894a0f7424
commit
e24ca294b6
2 changed files with 9 additions and 7 deletions
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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.",
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue