On 09.05.20 14:16, Dominik Vilsmeier wrote:

On 09.05.20 12:18, Alex Hall wrote:

On Sat, May 9, 2020 at 11:57 AM Dominik Vilsmeier
<dominik.vilsme...@gmx.de <mailto:dominik.vilsme...@gmx.de>> wrote:

    So as a practical step forward, what about providing a wrapper type
    which performs all operations elementwise on the operands. So for
    example:

         if all(elementwise(chars) == string):
             ...

    Here the `elementwise(chars) == string` part returns a generator
    which
    performs the `==` comparison element-by-element.


Now `==` has returned an object that's always truthy, which is pretty
dangerous.

That can be resolved by returning a custom generator type which
implements `def __bool__(self): raise TypeError('missing r.h.s.
operand')`.

After reading this again, I realized the error message is nonsensical in
this context. It should be rather something like: `TypeError('The truth
value of an elementwise comparison is ambiguous')` (again taking some
inspiration from Numpy).
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@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/X2N77J2I5KGNADQJ7GKLL3Z6NJ3RKGPC/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to