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

Use eval_type_backport on Python 3.9 if it's installed to resolve int | None etc. #773

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ashb
Copy link

@ashb ashb commented Nov 16, 2024

This uses the same module that pydantic does, and it allows people to use the
new pipe syntax if they have to support Python3.9 too -- very useful for
libraries.

(Also it works better with many type checkers which seem to mistakenly think
that with from __future__ import annotations means int| None will work,
but it doesn't out of the box.)

Fixes #771

@ashb
Copy link
Author

ashb commented Nov 16, 2024

@jcrist PTAL. I've put in a place for making it installed or not, but didn't do anything in this PR to run it with or without this.

Let me know if you'd like the structure something else too. Or I'm more than happy for you to push changes to my fork too.

…t | None` etc.

This uses the same module that pydantic does, and it allows people to use the
new pipe syntax if they have to support Python3.9 too -- very useful for
libraries.

(Also it works better with many type checkers which seem to mistakenly think
that with `from __future__ import annotations` means `int| None` will work,
but it doesn't out of the box.)
@ashb ashb force-pushed the py39_union_backport_support branch from ada02f0 to 3cc6d81 Compare November 16, 2024 14:41
@ashb
Copy link
Author

ashb commented Nov 16, 2024

(I thought about adding the test for this in test_common with a decoder, but this seemed to be more directly testing the code)

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.

Backport type annotation syntax support for older python versions
2 participants