Skip to content

Commit 3a2091a

Browse files
committed
Change origin of _BoolLiteral to Literal.
1 parent 01debeb commit 3a2091a

3 files changed

Lines changed: 9 additions & 19 deletions

File tree

typemap/type_eval/_eval_operators.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -275,21 +275,6 @@ def _eval_Bool(tp, *, ctx):
275275
return _eval_bool_tp(tp, ctx)
276276

277277

278-
@type_eval.register_evaluator(_BoolLiteral)
279-
@_lift_evaluated
280-
def _eval_BoolLiteral(tp, *, ctx):
281-
from typemap.typing import _BoolLiteralGenericAlias
282-
283-
if isinstance(tp, type):
284-
raise TypeError(f"Expected literal type, got '{tp.__name__}'")
285-
286-
# If already wrapped, just return it
287-
if isinstance(tp, _BoolLiteralGenericAlias):
288-
return tp
289-
290-
return _BoolLiteral[tp]
291-
292-
293278
##################################################################
294279

295280

typemap/type_eval/_typing_inspect.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,7 @@ def is_optional_type(t: Any) -> TypeGuard[UnionType]:
132132

133133

134134
def is_literal(t: Any) -> bool:
135-
from typemap.typing import _BoolLiteral
136-
137-
return is_generic_alias(t) and get_origin(t) in (Literal, _BoolLiteral)
135+
return is_generic_alias(t) and get_origin(t) is Literal # type: ignore [comparison-overlap]
138136

139137

140138
def get_head(t: Any) -> type | None:

typemap/typing.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,4 +307,11 @@ def __bool__(self):
307307

308308
@_SpecialForm
309309
def _BoolLiteral(self, tp):
310-
return _BoolLiteralGenericAlias(self, tp)
310+
if isinstance(tp, type):
311+
raise TypeError(f"Expected literal type, got '{tp.__name__}'")
312+
313+
# If already wrapped, just return it
314+
if isinstance(tp, _BoolLiteralGenericAlias):
315+
return tp
316+
317+
return _BoolLiteralGenericAlias(Literal, tp)

0 commit comments

Comments
 (0)