Skip to content
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