Skip to content

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

Closed

Description

@Fatal1ty
  • 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.

Activity

  1. Fatal1ty commented on Apr 19, 2023

    @Fatal1ty
    OwnerAuthor

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions