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

Make get_origin(Literal[...]) == Literal. #80

Merged
merged 1 commit into from Jun 19, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions test_typing_inspect.py
Expand Up @@ -337,6 +337,8 @@ def test_origin(self):
self.assertEqual(get_origin(ClassVar[int]), None)
self.assertEqual(get_origin(Generic), Generic)
self.assertEqual(get_origin(Generic[T]), Generic)
# Cannot use assertEqual on Py3.5.2.
self.assertIs(get_origin(Literal[42]), Literal)
if PY39:
self.assertEqual(get_origin(list[int]), list)
if GENERIC_TUPLE_PARAMETRIZABLE:
Expand Down
8 changes: 5 additions & 3 deletions typing_inspect.py
Expand Up @@ -66,10 +66,10 @@
WITH_FINAL = False

try: # python 3.6
from typing_extensions import _Literal
from typing_extensions import Literal
except ImportError: # python 2.7
try:
from typing import _Literal
from typing import Literal
except ImportError:
WITH_LITERAL = False

Expand Down Expand Up @@ -230,7 +230,7 @@ def is_literal_type(tp):
if NEW_TYPING:
return (tp is Literal or
isinstance(tp, typingGenericAlias) and tp.__origin__ is Literal)
return WITH_LITERAL and type(tp) is _Literal
return WITH_LITERAL and type(tp) is type(Literal)


def is_typevar(tp):
Expand Down Expand Up @@ -345,6 +345,8 @@ def get_origin(tp):
return Union
if is_tuple_type(tp):
return Tuple
if is_literal_type(tp):
return Literal

return None

Expand Down