Skip to content

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

Merged
jcrist merged 4 commits into
msgspec:mainfrom
ashb:py39_union_backport_support
Dec 27, 2024
Merged

jcrist merged 4 commits into
msgspec:mainfrom
ashb:py39_union_backport_support

Conversation

@ashb

@ashb ashb commented Nov 16, 2024 •

Copy link
Copy Markdown
Contributor

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

ashb commented Nov 16, 2024

Copy link
Copy Markdown
Contributor Author

@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

ashb commented Nov 16, 2024

Copy link
Copy Markdown
Contributor Author

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

@jcrist
jcrist merged commit 4418e5e into msgspec:main Dec 27, 2024
@jcrist

jcrist commented Dec 27, 2024

Copy link
Copy Markdown
Member

Thanks for the PR (and your patience here), this is in!

@ashb
ashb deleted the py39_union_backport_support branch January 23, 2025 10:17
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