On Thu, Sep 19, 2019 at 09:03:06AM +0200, Philippe Prados wrote:
> * You need __ror__ as well as __or__.
> No, in this situation, Python auto invoke ``__or__`` in case of ``__ror__``.
I don't think that Python will invoke ``__or__`` if the ``__ror__``
method is missing.
Testing in Python 3.8:
py> class Test(object):
... def __or__(self, other):
... return "Called __or__ method"
...
py> Test() | None # works
'Called __or__ method'
py> None | Test()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for |: 'NoneType' and 'Test'
Unless I have missed something, you need both ``__ror__`` as well as
``__or__`` to make it work correctly.
> * The static types in typing are not instances of type, so you need to
> work out what to do with them.
> I do not understand the remark. My patch of 'mypy' accept this new syntax.
This is not just about mypy static checks, it is also about Python
runtime checks.
[...]
> Where I can find the argument to explain why this have been deliberated
> removed in 3.6 ?
Try the What's New file for 3.6, and the bug tracker.
> In my implementation, they affect just Union. isinstance() can now accept
> type, Tuple or Union.
What about issubclass?
> * What about except clauses? Shouldn’t they take unions if isinstance
> does? How does that work?
> Good question. To accept `except TypeError | ZeroDivisionError:` in place
> of `except (TypeError, ZeroDivisionError):`, the impact is bigger, but why
> not ?
I don't think this will be a problem. The except clause will accept any
expression:
py> try:
... 1/0
... except None or [] or 0 or ZeroDivisionError:
... print("caught divide by zero")
...
caught divide by zero
So long as the expression ``TypeError | ZeroDivisionError`` returns a
subclass of BaseException, everything should Just Work with no syntax
changes.
--
Steven
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/ASOXIHDJUI2SXMJWNU6YRTCKGFW7RV76/
Code of Conduct: http://python.org/psf/codeofconduct/