[issue45857] PEP 604 Union syntax does not support forward references
Ken Jin
report at bugs.python.org
Mon Nov 22 08:33:37 EST 2021
Ken Jin <kenjin4096 at gmail.com> added the comment:
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?
----------
status: open -> pending
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45857>
_______________________________________
More information about the Python-bugs-list
mailing list