New submission from Serhiy Storchaka <storchaka+cpyt...@gmail.com>:
All errors raised in the __iter__ method are masked by the TypeError exception in the "in" operator and functions operator.contains(), operator.indexOf() and operator.countOf(). >>> class BadIterable: ... def __iter__(self): ... 1/0 ... >>> >>> 1 in BadIterable() Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: argument of type 'BadIterable' is not iterable It includes exceptions out of control of the programmer like MemoryError and KeyboardInterrupt. Converting them to TypeError can lead to weird errors or incorrect results. See also similar issue26407. ---------- components: Interpreter Core messages: 370372 nosy: serhiy.storchaka priority: normal severity: normal status: open title: Unexpected errors in __iter__ are masked in "in" and the operator module type: behavior versions: Python 3.10, Python 3.6, Python 3.7, Python 3.8, Python 3.9 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue40824> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com