Skip to content

Commit ce96caa

Browse files
authored
Fix literals (#260)
1 parent edb9f25 commit ce96caa

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

simple_parsing/utils.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@
3838

3939
from typing_extensions import Literal, Protocol, TypeGuard, get_args, get_origin
4040

41+
# There are cases where typing.Literal doesn't match typing_extensions.Literal:
42+
# https://github.com/python/typing_extensions/pull/148
43+
try:
44+
from typing import Literal as LiteralAlt
45+
except ImportError:
46+
LiteralAlt = Literal # type: ignore
47+
4148

4249
# NOTE: Copied from typing_inspect.
4350
def is_typevar(t) -> bool:
@@ -262,7 +269,7 @@ def is_literal(t: type) -> bool:
262269
>>> is_literal(Optional[Literal[1,2]])
263270
False
264271
"""
265-
return get_origin(t) is Literal
272+
return get_origin(t) in (Literal, LiteralAlt)
266273

267274

268275
def is_list(t: type) -> bool:

0 commit comments

Comments
 (0)