Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes TypeInferenceProvider breakage with empty cache. #476

Merged
merged 2 commits into from
Apr 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions libcst/metadata/tests/test_type_inference_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,10 @@ def test_simple_class_types(self, source_path: Path, data_path: Path) -> None:
cache={TypeInferenceProvider: data},
)
_test_simple_class_helper(self, wrapper)

def test_with_empty_cache(self) -> None:
tip = TypeInferenceProvider({})
self.assertEqual(tip.lookup, {})

tip = TypeInferenceProvider(PyreData())
self.assertEqual(tip.lookup, {})
5 changes: 3 additions & 2 deletions libcst/metadata/type_inference_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class InferredType(TypedDict):
annotation: str


class PyreData(TypedDict):
class PyreData(TypedDict, total=False):
types: Sequence[InferredType]


Expand Down Expand Up @@ -75,7 +75,8 @@ def gen_cache(
def __init__(self, cache: PyreData) -> None:
super().__init__(cache)
lookup: Dict[CodeRange, str] = {}
for item in cache["types"]:
cache_types = cache.get("types", [])
for item in cache_types:
location = item["location"]
start = location["start"]
end = location["stop"]
Expand Down