JelleZijlstra / autotyping

Automatically add simple type annotations to your code
215 stars 18 forks source link

`__contains__` can return other types #45

Closed sobolevn closed 1 year ago

sobolevn commented 1 year 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 1 year 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.