Skip to content

Commit

Permalink
test: add regression test for dropping cache on namespace change
Browse files Browse the repository at this point in the history
  • Loading branch information
shiftinv committed Oct 26, 2023
1 parent 131adbf commit d9a36c8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,26 @@ def test_forwardref_mixed(self) -> None:
annotation = utils_helper_module.GenericListAlias["LocalIntOrStr"]
assert utils.resolve_annotation(annotation, globals(), locals(), {}) == List[LocalIntOrStr]

# two different forwardrefs with same name
def test_forwardref_duplicate(self) -> None:
DuplicateAlias = int

# first, resolve an annotation where `DuplicateAlias` resolves to the local int
cache = {}
assert (
utils.resolve_annotation(List["DuplicateAlias"], globals(), locals(), cache)
== List[int]
)

# then, resolve an annotation where the globalns changes and `DuplicateAlias` resolves to something else
# (i.e. this should not resolve to `List[int]` despite {"DuplicateAlias": int} in the cache)
assert (
utils.resolve_annotation(
utils_helper_module.ListWithDuplicateAlias, globals(), locals(), cache
)
== List[str]
)


@pytest.mark.parametrize(
("dt", "style", "expected"),
Expand Down
3 changes: 3 additions & 0 deletions tests/utils_helper_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@

T = TypeVar("T")
GenericListAlias = TypeAliasType("GenericListAlias", List[T], type_params=(T,))

DuplicateAlias = str
ListWithDuplicateAlias = TypeAliasType("ListWithDuplicateAlias", List["DuplicateAlias"])

0 comments on commit d9a36c8

Please sign in to comment.