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

[red-knot] understand type[A | B] where A and B are both classes #14703

Closed
Tracked by #14172
Glyphack opened this issue Dec 1, 2024 · 1 comment · Fixed by #14830
Closed
Tracked by #14172

[red-knot] understand type[A | B] where A and B are both classes #14703

Glyphack opened this issue Dec 1, 2024 · 1 comment · Fixed by #14830
Assignees
Labels
red-knot Multi-file analysis & type inference

Comments

@Glyphack
Copy link
Contributor

Glyphack commented Dec 1, 2024

(part of #14172)
type[A | B] Is equivalent to an enum of type[A] | type[B].

There are not a lot of edge cases looking at the tests here: https://github.com/python/typing/blob/main/conformance/tests/specialtypes_type.py#L50

@sbrugman
Copy link
Contributor

sbrugman commented Dec 1, 2024

Just a heads-up for future reference: red-knot should produce a violation when the type[A, B] syntax is used.

This came up in this PR

carljm added a commit that referenced this issue Dec 7, 2024
resolves #14703

I decided to use recursion to get the type, so if anything is added to
the single element inference it will be applied for the union.
Also added this
[change](#14703 (comment))
in this PR since it was easy.

---------

Co-authored-by: Carl Meyer <carl@astral.sh>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
red-knot Multi-file analysis & type inference
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants