[Python-ideas] + operator on generators

Steven D'Aprano steve at pearwood.info
Tue Jun 27 07:10:22 EDT 2017


On Mon, Jun 26, 2017 at 01:23:36PM +1000, Steven D'Aprano wrote:

> The downside to this proposal is that it adds some conceptual complexity 
> to Python operators. Apart from `is` and `is not`, all Python operators 
> call one or more dunder methods. This is (as far as I know) the first 
> operator which has fall-back functionality if the dunder methods aren't 
> defined.

I remembered there is a precedent here. The == operator tries __eq__ 
before falling back on object identity, at least in Python 2.

py> getattr(object(), '__eq__')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'object' object has no attribute '__eq__'
py> object() == object()
False


-- 
Steve


More information about the Python-ideas mailing list