Skip to content
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
4 changes: 4 additions & 0 deletions tests/test_type_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,10 @@ def test_eval_literal_idempotent_01():
t = nt


def test_is_literal_true_vs_one():
assert eval_typing(Is[Literal[True], Literal[1]]) is False


def test_callable_to_signature():
from typemap.type_eval._eval_operators import _callable_type_to_signature
from typemap.typing import Param
Expand Down
12 changes: 5 additions & 7 deletions typemap/type_eval/_subsim.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import typing


from . import _typing_inspect


__all__ = ("issubsimilar",)


Expand Down Expand Up @@ -38,11 +36,11 @@ def issubsimilar(lhs: typing.Any, rhs: typing.Any) -> bool:
return issubclass(lhs, rhs)

# literal <:? literal
elif bool(
_typing_inspect.is_literal(lhs) and _typing_inspect.is_literal(rhs)
):
rhs_args = set(typing.get_args(rhs))
return all(lv in rhs_args for lv in typing.get_args(lhs))
elif _typing_inspect.is_literal(lhs) and _typing_inspect.is_literal(rhs):
# We need to check both value and type, since True == 1 but
# Literal[True] should not be a subtype of Literal[1]
rhs_args = {(t, type(t)) for t in typing.get_args(rhs)}
return all((lv, type(lv)) in rhs_args for lv in typing.get_args(lhs))

# XXX: This case is kind of a hack, to support NoLiterals.
elif rhs is typing.Literal:
Expand Down