On Mon., 18 Nov. 2019, 6:52 am MRAB, email@example.com wrote:
On 2019-11-17 20:09, Ivan Levkivskyi wrote:
To add some more input about forward references, here are couple of thoughts:
- I think ideally we should support forward references to the same
extent they are currently supported: i.e. Union[None, "ForwardRef"], Union["OtherForwardRef", None], and Union["ForwardRef", "OtherForwardRef"] should all be supported. The last one looks the hardest, in the sense that it looks like we will need to add `str.__or__()` to support these forms.
I'm not sure I like the thought of adding `str.__or__()` because it would mean that "Foo" | "Bar" becomes valid and returns a type, which is unexpected.
Perhaps an alternative would be to add 'Forward' to make it explicit:
Forward("ForwardRef") | Forward("OtherForwardRef")
Forward("ForwardRef") | "OtherForwardRef"
Or require that the entire expression be quoted in that case: "ForwardRef | OtherForwardRef"
I wouldn't personally object to an explicit "typing.Forward" construct, though.