On 29/08/2019 16:30:49, Chris Angelico wrote:
isinstance(3, Union[str, int]) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python3.9/typing.py", line 764, in __instancecheck__ return self.__subclasscheck__(type(obj)) File "/usr/local/lib/python3.9/typing.py", line 772, in __subclasscheck__ raise TypeError("Subscripted generics cannot be used with" TypeError: Subscripted generics cannot be used with class and instance checks
If they were permitted, then instance checks could use an extremely clean-looking notation for "any of these":
isinstance(x, str | int) ==> "is x an instance of str or int"
Er, is that necessary when you can already write isinstance(x, (str, int))
It's very common for novices to write "if x == 3 or 5:", and I'm not sure whether that's an argument in favour or against.
ChrisA _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/RJ55YR... Code of Conduct: http://python.org/psf/codeofconduct/
--- This email has been checked for viruses by AVG. https://www.avg.com