Skip to content

Test is_proper_subtype with string literals #14011

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
25 changes: 25 additions & 0 deletions mypy/test/testtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,31 @@ def test_is_proper_subtype_and_subtype_literal_types(self) -> None:
assert is_subtype(lit1, fx.anyt)
assert is_subtype(fx.anyt, lit1)

def test_is_proper_subtype_literal_str_types(self) -> None:
fx = self.fx

lit_foo = LiteralType("foo", fx.str_type)
assert is_proper_subtype(lit_foo, lit_foo)

lit_also_foo = LiteralType("foo", fx.str_type)
assert is_proper_subtype(lit_foo, lit_also_foo)
assert is_proper_subtype(lit_also_foo, lit_foo)

lit_bar = LiteralType("bar", fx.str_type)
assert not is_proper_subtype(lit_foo, lit_bar)
assert not is_proper_subtype(lit_bar, lit_foo)

str_type = fx.str_type
assert is_proper_subtype(lit_foo, str_type)
assert not is_proper_subtype(str_type, lit_foo)

lit_foo_context_sensitive = Instance(fx.str_type_info, [], last_known_value=lit_foo)
assert is_proper_subtype(lit_foo_context_sensitive, str_type)
assert is_proper_subtype(str_type, lit_foo_context_sensitive)

assert not is_proper_subtype(lit_foo_context_sensitive, lit_bar)
assert is_proper_subtype(lit_bar, lit_foo_context_sensitive)

def test_subtype_aliases(self) -> None:
A1, _ = self.fx.def_alias_1(self.fx.a)
AA1, _ = self.fx.def_alias_1(self.fx.a)
Expand Down