Skip to content

Allow writing union types as X | Y #3419

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

Closed
moreal opened this issue Nov 6, 2021 · 6 comments
Closed

Allow writing union types as X | Y #3419

moreal opened this issue Nov 6, 2021 · 6 comments

Comments

@moreal
Copy link
Contributor

moreal commented Nov 6, 2021

Feature

Since CPython 3.10 version, it became to allow writing union types as X | Y (e.g. int | str).

Python Documentation

@rtpg
Copy link

rtpg commented Nov 7, 2021

I'm kinda curious about this one, have you started looking at this one already? If not I'll take a shot

@moreal
Copy link
Contributor Author

moreal commented Nov 7, 2021

@rtpg No, I didn't. I opened this issue as a task card. You can take this one. 😉

@youknowone
Copy link
Member

youknowone commented Nov 28, 2021

__or__ and __ror__ needs to be implemented in type. type is defined in vm/src/builtins/pytype.rs as PyType struct.
Other types __or__ implementation will be useful. it can be found in any type implementing | operator, like int, set and other types. For those types, search for fn or in vm/src/builtins/<typename>.rs.

By looking at links of the the issue, CPython seems to implement Union in C now. I think we can use python version at the first - if we are not going to implement Union type at the same time.
To bring Union from typing.py, VirtualMachine::import is useful. Search for vm.import for the use cases.
To get attribute __getitem__ and invoke the method, search for vm.get_attribute_opt and vm.invoke.

@hrchu
Copy link
Contributor

hrchu commented Nov 28, 2021

Take this one in PyCcon APAC 2021 sprint

@youknowone
Copy link
Member

@moreal is this done?

@moreal
Copy link
Contributor Author

moreal commented Mar 12, 2022

@moreal is this done?

@youknowone As I know, I believe it is done.

@moreal moreal closed this as completed Mar 12, 2022
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

No branches or pull requests

4 participants