06.02.20 21:38, Brandt Bucher пише:
One issue that's come up during PR review with Guido and Serhiy is, when
evaluating `a | b`, whether or not the default implementation should call an
overridden `copy()` method on `a` in order to create an instance of the correct
subclass (rather than a plain-ol' `dict`).
It would create an exception of two rules:
1. Operators on subclasses of builtin classes do not depend on
overridden methods of arguments (except the corresponding dunder
method). `list.__add__` and `set.__or__` do not call copy() and
extend()/update(). You should override the corresponding dunder method
to change the behavior of the operator.
2. Operators do not depend on non-dunder methods.
This looks to me as a direct violation of the principle "Special cases
aren't special enough to break the rules."
I think the standard handling of subclasses in Python builtins is wrong, and I don't wish
to emulate that wrong behaviour without a really good reason. Or at least a better reason
than "other methods break subclassing unless explicitly overloaded, so this should
do so too". Or at least not without a fight :-)
We can discuss and change the standard handling of subclasses in Python
builtins. But if it be changed, it should be changed for all builtin
classes, without exceptions and special cases.
This could resolve a problem with rule 1. But there is still a problem
with rule 2.
_______________________________________________
Python-Dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/4NDSEYFAHZBZOPIYKC4URMFAUGAIE42G/
Code of Conduct: http://python.org/psf/codeofconduct/