I think it's a good idea to allow unions in isinstance() (and issubclass()).

I recall occasionally getting questions about this from Dropbox engineers. The use case is usually having a list of types that is used both in isinstance() and in a type annotation, and trying to factor it so that if the list of acceptable types is changed, only one place has to be changed (following "DRY" principle).

I've seen this often enough that I think it's a good idea, and PEP 604 will require having a builtin representation of unions anyway, so the implementation should be straightforward.

On Thu, Oct 3, 2019 at 10:04 AM Philippe Prados <philippe.prados@gmail.com> wrote:
Hello everybody,

After the previous discussions, a new simplified version of PEP-0604 was published.

I propose to add a similar syntax of Scala 3 in Python, to accept an or operator.

# Operator for Union
assert( int | str == Union[int,str])


The isinstance() and issubclass() were extended to accept this new syntax:

isinstance(int, int | str)
It's not really explored.
To accept this evolution, the object Union (and dependencies) now be available as a builtin.

Your remarks are welcome.

Philippe
_______________________________________________
Typing-sig mailing list -- typing-sig@python.org
To unsubscribe send an email to typing-sig-leave@python.org
https://mail.python.org/mailman3/lists/typing-sig.python.org/


--
--Guido van Rossum (python.org/~guido)
Pronouns: he/him (why is my pronoun here?)