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

Fix typing.Literal support for Python 3.9 #104

Merged
merged 1 commit into from
Apr 24, 2023

Conversation

RA80533
Copy link
Contributor

@RA80533 RA80533 commented Apr 24, 2023

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).

  • is_literal_type() was changed to check PY_310_MIN instead of PY_39_MIN (and check for PY_39 separately)
  • test_is_literal_unsupported_python() was updated to mock the updated conditions
  • test_is_literal_py39() was added to test backwards compatibility for Python versions [3.9.0, 3.9.1)

Fixes #103

tests/test_meta.py Outdated Show resolved Hide resolved
tests/test_meta.py Outdated Show resolved Hide resolved
tests/test_meta.py Outdated Show resolved Hide resolved
@RA80533 RA80533 requested a review from Fatal1ty April 24, 2023 18:40
Copy link
Owner

@Fatal1ty Fatal1ty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Can you squash and force push all the commits as one to retain you as an author before the merge?

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.
@Fatal1ty Fatal1ty merged commit b99a1f6 into Fatal1ty:master Apr 24, 2023
16 checks passed
@Fatal1ty
Copy link
Owner

Thanks 👍

@RA80533 RA80533 deleted the fix/literal-support branch April 25, 2023 17:01
@fabiopedrosa
Copy link

@Fatal1ty can we get this fix into a release please?

@Fatal1ty
Copy link
Owner

Fatal1ty commented Jun 5, 2023

@fabiopedrosa Can it wait a bit more? I'm planning to make a release this or next week after finishing the following issues:

Good news is I'm almost done with the first two, just need to update the documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

typing.Literal isn't supported properly on Python 3.9.0
3 participants