Skip to content

Commit

Permalink
Check PY_310_MIN instead of PY_39_MIN
Browse files Browse the repository at this point in the history
Python 3.9.1 changed the `type()` of `Literal` instances to be
`_LiteralGenericAlias` instead of `_GenericAlias`.

`is_literal_type()` assumed the change took place in Python 3.9.0 and
checked for it accordingly. Because the assumption was incorrect, it
failed to detect `Literal` types in Python versions [3.9.0, 3.9.1).

This commit changes `is_literal_type()` to check `PY_310_MIN` instead of
`PY_39_MIN` to fix the issue.
  • Loading branch information
RA80533 committed Apr 24, 2023
1 parent 262c856 commit aba3857
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 3 additions & 2 deletions mashumaro/core/meta/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
PY_37,
PY_38,
PY_38_MIN,
PY_39,
PY_39_MIN,
PY_310_MIN,
PY_311_MIN,
Expand Down Expand Up @@ -362,10 +363,10 @@ def is_annotated(typ: Type) -> bool:


def is_literal(typ: Type) -> bool:
if PY_37 or PY_38:
if PY_37 or PY_38 or PY_39:
with suppress(AttributeError):
return is_generic(typ) and get_generic_name(typ, True) == "Literal"
elif PY_39_MIN:
elif PY_310_MIN:
with suppress(AttributeError):
# noinspection PyProtectedMember
# noinspection PyUnresolvedReferences
Expand Down
3 changes: 2 additions & 1 deletion tests/test_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ def test_is_init_var_unsupported_python(mocker):
def test_is_literal_unsupported_python(mocker):
mocker.patch("mashumaro.core.meta.helpers.PY_37", False)
mocker.patch("mashumaro.core.meta.helpers.PY_38", False)
mocker.patch("mashumaro.core.meta.helpers.PY_39_MIN", False)
mocker.patch("mashumaro.core.meta.helpers.PY_39", False)
mocker.patch("mashumaro.core.meta.helpers.PY_310_MIN", False)
assert not is_literal(typing_extensions.Literal[1])


Expand Down

0 comments on commit aba3857

Please sign in to comment.