Special method
__aiter__
cannot be converted into a generator 940
941 async def __aiter__(self) -> t.AsyncIterator[t.Any]:
942 for _ in ():
943 yield 944
945 def __bool__(self) -> bool:
946 return False
Description
Not all magic method can used as generator function as Python's datamodel is strict.
A function or method which uses the yield statement is called a generator function. Magic methods in Python are the special methods that start and end with the double underscores.
Use of yield inside following magic methods in forbidden:
__ixor__
__rrshift__
__lt__
__round__
__init__
__invert__
__pos__
__rdivmod__
__ceil__
__rsub__
__mul__
__eq__
__iadd__
__enter__
__index__
__aiter__
__radd__
__init_subclass__
__imul__
__matmul__
__ilshift__
__del__
__set__
__ne__
__truediv__
__sub__
__rmatmul__
__floordiv__
__rfloordiv__
__rxor__
__rpow__
__complex__
__iand__
__rmul__
__le__
__gt__
__contains__
__itruediv__
__missing__
__rtruediv__
__floor__
__get__
__int__
__imod__
__getattribute__
__new__
__len__
__getattr__
__imatmul__
__rlshift__
__instancecheck__
__divmod__
__isub__
__or__
__neg__
__bytes__
__ior__
__aexit__
__setattr__
__length_hint__
__rand__
__rshift__
__exit__
__lshift__
__delattr__
__subclasscheck__
__delete__
__pow__
__set_name__
__irshift__
__format__
__repr__
__anext__
__float__
__aenter__
__rmod__
__class_getitem__
__setitem__
__await__
__str__
__and__
__getitem__
__ifloordiv__
__delitem__
__ipow__
__hash__
__ge__
__trunc__
__dir__
__mod__
__ror__
__reversed__
__xor__
__abs__
__add__
__bool__
You can remove yield
from the magic method or rename it to be a custom method.
Bad practice
class MyClass:
def __init__(self):
yield 1
Recommended
class MyClass:
def __init__(self):
pass