I had a DRF (django-rest-framework) ViewSet class with some methods, and one of them is
def foobar(foo: list[str], bar: list[int]) -> bool:
return ...
Today, when I implemented the def list method of the common ViewSet class, mypy started considering this new function instead the builtin list for the list[str] giving me some errors:
error: Function "path.to.the.class.list" is not valid as a type [valid-type]
note: Perhaps you need "Callable[...]" or a callback protocol?
error: "list?[builtins.str]" has no attribute "__iter__" (not iterable) [attr-defined]
The problem is clear, the new function does shadowing. The question is how do you usually avoid this problem? In my personal case find a solution is quiet easy, I can just move my function to another class / file / outside this class and everything will work as expected.
I would like to collect other ideas.