Skip to content

Support Python 3.10 type unions - #75

Merged
jcrist merged 1 commit into
masterfrom
310-union-types
Feb 24, 2022
Merged

jcrist merged 1 commit into
masterfrom
310-union-types

Conversation

@jcrist

@jcrist jcrist commented Feb 24, 2022

Copy link
Copy Markdown
Member

I thought these already worked, but they didn't. Type unions using the
int | None syntax create a types.UnionType object, not a
typing.Union object. Unfortunately types.UnionType doesn't define
__origin__ (like all other generic types do), so this wasn't being
properly handled by the previous logic. This PR fixes this and adds a
test for Python 3.10+.

I thought these already worked, but they didn't. Type unions using the
`int | None` syntax create a `types.UnionType` object, not a
`typing.Union` object. Unfortunately `types.UnionType` doesn't define
`__origin__` (like all other generic types do), so this wasn't being
properly handled by the previous logic. This PR fixes this and adds a
test for Python 3.10+.
@jcrist
jcrist merged commit df9a3b0 into master Feb 24, 2022
@jcrist
jcrist deleted the 310-union-types branch February 24, 2022 19:02
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.

1 participant