Skip to content

Commit

Permalink
Fixes TypeInferenceProvider breakage with empty cache. (#476)
Browse files Browse the repository at this point in the history
* Fixes TypeInferenceProvider breakage with empty cache.
  • Loading branch information
lisroach committed Apr 8, 2021
1 parent e759ca8 commit 068b905
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
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

0 comments on commit 068b905

Please sign in to comment.