Skip to content

Commit

Permalink
Merge pull request #104 from RA80533/fix/literal-support
Browse files Browse the repository at this point in the history
Fix `typing.Literal` support for Python 3.9
  • Loading branch information
Fatal1ty committed Apr 24, 2023
2 parents 262c856 + aba3857 commit b99a1f6
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 b99a1f6

Please sign in to comment.