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

typing.Literal isn't supported properly on Python 3.9.0 #103

Closed
Fatal1ty opened this issue Apr 19, 2023 · 1 comment · Fixed by #104
Closed

typing.Literal isn't supported properly on Python 3.9.0 #103

Fatal1ty opened this issue Apr 19, 2023 · 1 comment · Fixed by #104
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@Fatal1ty
Copy link
Owner

  • mashumaro version: 3.7
  • Python version: 3.9.0
  • Operating System: macOS 13.2.1

Description

Function is_literal doesn't return True for typing.Literal[42] on Python 3.9.0. Type of typing.Literal instances has been changed from _GenericAlias to _LiteralGenericAlias since 3.9.1.

@Fatal1ty
Copy link
Owner Author

We should add or PY_39 to the first condition and replace PY_39_MIN with PY_310_MIN here:

def is_literal(typ: Type) -> bool:
if PY_37 or PY_38:
with suppress(AttributeError):
return is_generic(typ) and get_generic_name(typ, True) == "Literal"
elif PY_39_MIN:
with suppress(AttributeError):
# noinspection PyProtectedMember
# noinspection PyUnresolvedReferences
return type(typ) is typing._LiteralGenericAlias # type: ignore
return False

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant