mirror of
https://github.com/Instagram/LibCST.git
synced 2025-12-23 10:35:53 +00:00
[metadata] make QualifiedNameProvider typing more specific
This commit is contained in:
parent
94e40d84ac
commit
f4eb9d197e
2 changed files with 4 additions and 12 deletions
|
|
@ -858,14 +858,12 @@ class QualifiedNameVisitor(cst.CSTVisitor):
|
|||
if scope:
|
||||
self.provider.set_metadata(node, scope.get_qualified_names_for(node))
|
||||
else:
|
||||
self.provider.set_metadata(node, {})
|
||||
self.provider.set_metadata(node, set())
|
||||
super().on_visit(node)
|
||||
return True
|
||||
|
||||
|
||||
class QualifiedNameProvider(
|
||||
BatchableMetadataProvider[Optional[Collection[QualifiedName]]]
|
||||
):
|
||||
class QualifiedNameProvider(BatchableMetadataProvider[Collection[QualifiedName]]):
|
||||
"""
|
||||
Compute possible qualified names of a variable CSTNode
|
||||
(extends `PEP-3155 <https://www.python.org/dev/peps/pep-3155/>`_).
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
# pyre-strict
|
||||
|
||||
from textwrap import dedent
|
||||
from typing import Collection, Mapping, Tuple, cast
|
||||
from typing import Collection, Mapping, Tuple
|
||||
|
||||
import libcst as cst
|
||||
from libcst import ensure_type
|
||||
|
|
@ -23,13 +23,7 @@ def get_qualified_name_metadata_provider(
|
|||
module_str: str
|
||||
) -> Tuple[cst.Module, Mapping[cst.CSTNode, Collection[QualifiedName]]]:
|
||||
wrapper = MetadataWrapper(cst.parse_module(dedent(module_str)))
|
||||
return (
|
||||
wrapper.module,
|
||||
cast(
|
||||
Mapping[cst.CSTNode, Collection[QualifiedName]],
|
||||
wrapper.resolve(QualifiedNameProvider),
|
||||
), # we're sure every node has an associated scope
|
||||
)
|
||||
return wrapper.module, wrapper.resolve(QualifiedNameProvider)
|
||||
|
||||
|
||||
class ScopeProviderTest(UnitTest):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue