JelleZijlstra / autotyping

Automatically add simple type annotations to your code
238 stars 20 forks source link

`__contains__` can return other types #45

Closed sobolevn closed 2 years ago

sobolevn commented 2 years ago

The result of __contains__ is casted to bool.

Examples:

>>> class A:
...     def __contains__(self, other):
...         return other
... 
>>> 'abc' in A()
True
>>> None in A()
False

So, technically -> bool is not correct 🤔

JelleZijlstra commented 2 years ago

And technically __len__ can return int | SupportsIndex. I think within the scope of this project, returning bool is fine because that's what __contains__ is supposed to return.