This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author kj
Recipients AlexWaygood, TNThung, eric.smith, gvanrossum, kj
Date 2021-11-22.13:33:37
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1637588017.65.0.588450807953.issue45857@roundup.psfhosted.org>
In-reply-to
Content
I think I saw a similar bug report elsewhere (or maybe I'm misremembering). Anyways, Eric is right, the correct way is to wrap the entire thing, so "Foo|int" instead of "Foo"|int.

@Alex you brought up some good suggestions, I'll try to address them:

> Arguably, either the implementation should be altered to support forward references

Unfortunately that's more complex than it seems. The original draft PEP 604 proposed implementation actually imported Union from typing.py, and I recall Guido disliking the idea that a builtin type should depend on typing.py. I have to agree with that philosophy here. I also don't think the alternative -- implementing a builtin ForwardRef type isn't worth the complexity unless our situation changes.

> the documentation at https://docs.python.org/3/library/stdtypes.html#union-type should be altered to make clear that ...

The first line says: "A union object holds the value of the | (bitwise or) operation on multiple type objects." It says *type objects*, which strings don't belong to.

@TNThung does Eric's suggestion work for you? Or do you need something else?
History
Date User Action Args
2021-11-22 13:33:37kjsetrecipients: + kj, gvanrossum, eric.smith, AlexWaygood, TNThung
2021-11-22 13:33:37kjsetmessageid: <1637588017.65.0.588450807953.issue45857@roundup.psfhosted.org>
2021-11-22 13:33:37kjlinkissue45857 messages
2021-11-22 13:33:37kjcreate