[issue45857] PEP 604 Union syntax does not support forward references

2021-11-22 Thread Alex Waygood
Alex Waygood added the comment: Thanks, Ken! To clarify: I agree that changing the implementation here would probably be a bad way to go: it would be foolish to try to replicate all the functionality of the typing module as builtins. I also think the existing documentation at

[issue45857] PEP 604 Union syntax does not support forward references

2021-11-22 Thread Ken Jin
Ken Jin 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,

[issue45857] PEP 604 Union syntax does not support forward references

2021-11-21 Thread Alex Waygood
Alex Waygood added the comment: Arguably, either the implementation should be altered to support forward references, or the documentation at https://docs.python.org/3/library/stdtypes.html#union-type should be altered to make clear that, when type-hinting a union that includes a forward

[issue45857] PEP 604 Union syntax does not support forward references

2021-11-21 Thread Eric V. Smith
Eric V. Smith added the comment: Presumably the correct way to do this is: def __init__(self, tmp: "Foo|int"): That is, the entire type hint is a string. -- nosy: +eric.smith ___ Python tracker

[issue45857] PEP 604 Union syntax does not support forward references

2021-11-21 Thread Alex Waygood
Alex Waygood added the comment: Reproduced on 3.11. The error occurs if a type is on the left-hand-side of the operand, as well as if a type is on the right-hand-side: ``` >>> int | "str" Traceback (most recent call last): File "", line 1, in TypeError: unsupported operand type(s) for |: