What about making typing.Union a re-export of types.Union? On Wed, Jul 29, 2020, 15:26 Guido van Rossum <guido@python.org> wrote:
Because we don't want to have to import the full typing module into the C code. Philippe's prototype tried that and it was not a success.
We did this way for GenericAlias (the type returned by `list[int]`) as well.
--Guido
On Wed, Jul 29, 2020 at 3:06 PM Luciano Ramalho <luciano@ramalho.org> wrote:
Thanks for the update, Guido.
Why is it necessary to create `types.Union`? Why not enable `typing.Union` to play that role too?
Best,
Luciano
On Wed, Jul 29, 2020 at 4:03 PM Guido van Rossum <guido@python.org> wrote:
Here's a status update for PEP 604:
https://www.python.org/dev/peps/pep-0604/
- Ivan has asked the SC to find another PEP delegate for personal
reasons, and the SC has asked me to step up in his place. Philippe, the PEP's author, has agreed.
- Maggie Moss has volunteered to write an implementation which is
currently in progress at https://github.com/python/cpython/pull/21515.
- I am quite positive regarding the PEP, I just think we need to
tighten the specification some more, especially in corner cases and for interoperability with types defined in typing.py. I will work with Maggie and Philippe on this. I see no problem getting this into 3.10. It will make a nice complement to the list[int] notation introduced in 3.9 by PEP 585.
Here's a summary of the key points from the PEP:
- `int | str` represents the union of `int` and `str` - There will be a new extension type, `types.Union` (1), to represent
unions created using `|`
- Such types will be acceptable in `isinstance(x, t)` and `issubclass(C, t)`
The rest is elaboration; most semantics are derived from existing semantics of `typing.Union[]`. We also strive for decent interoperability with the `typing` module.
(1) Beware! The existing union notation uses `typing.Union`; the new notation uses `types.Union`.
-- --Guido van Rossum (python.org/~guido) Pronouns: he/him (why is my pronoun here?) _______________________________________________ Typing-sig mailing list -- typing-sig@python.org To unsubscribe send an email to typing-sig-leave@python.org https://mail.python.org/mailman3/lists/typing-sig.python.org/ Member address: luciano@ramalho.org
-- Luciano Ramalho | Author of Fluent Python (O'Reilly, 2015) | http://shop.oreilly.com/product/0636920032519.do | Technical Principal at ThoughtWorks | Twitter: @ramalhoorg
-- --Guido van Rossum (python.org/~guido) *Pronouns: he/him **(why is my pronoun here?)* <http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-c...> _______________________________________________ Typing-sig mailing list -- typing-sig@python.org To unsubscribe send an email to typing-sig-leave@python.org https://mail.python.org/mailman3/lists/typing-sig.python.org/ Member address: njs@pobox.com