
On Fri, Aug 30, 2019 at 5:46 AM Andrew Barnert via Python-ideas <python-ideas@python.org> wrote:
On Aug 29, 2019, at 12:09, Dominik Vilsmeier <dominik.vilsmeier@gmx.de> wrote:
What about using `(int, str)` for indicating a `Union`? This doesn't have compatibility issues and it's similar to `isinstance(foo, (int, str))`, so it should be fairly intuitive:
def bar(foo: (int, str) = 0): ...
In most languages with similar-ish type syntax, (int, str) means Tuple[int, str], not Union[int, str]. Scala and TypeScript copied this from ML just like Haskell and F# did. And I’d bet this is the main reason that {str, int} rather than (str, int) was proposed the first time around.
But, balanced against the long-standing Python-specific use of tuples for small numbers of alternatives, including alternative types in places like isinstance, except, etc.? Maybe that beats the cross-linguistic issue.
Either one seems a lot better than breaking backward compatibility by adding new operator methods to the type type.
How does that break backward compat? ChrisA