On Fri, Aug 30, 2019 at 8:43 AM Guido van Rossum <guido@python.org> wrote:
On Thu, Aug 29, 2019 at 3:33 PM Chris Angelico <rosuav@gmail.com> wrote:
On Fri, Aug 30, 2019 at 8:28 AM Guido van Rossum <guido@python.org> wrote:
Open question: at runtime, what should `int | str` return? I don't want this to have to import the typing module. Maybe we could make a very simple `Union` builtin. This can then also be used by `~int` (which is equivalent to `int | None`).
Would it be okay to have a very simple Union builtin now, and it just always returns exactly that, and then in the future it might potentially actually return Union[int, str] ?
I'm not pushing for it *now*, but it would be extremely handy in the future to be able to say isinstance(3, int|str) and have it be meaningful.
Are you suggesting we introduce the "very simple Union builtin" earlier than the "int | str" notation/implementation? Why? 3.8 is closed for features, so it would be 3.9 at the earliest -- plenty of time to implement this right (including `isinstance(x, int|str)`).
I do think we should probably review PEP 585 before doing anything about unions specifically -- likely there are bigger fish to fry. (And PEP 585 has not received much discussion.)
No, I mean that at run-time, int|str might return a very simple object in 3.9, rather than everything that you'd need to grab from importing typing. Wondering if doing so would close off the possibility of, in 3.12 or something, making it a more directly usable "type union" that has other value. ChrisA