Closed omarandlorraine closed 2 years ago
It looks like mypy does handle this situation:
mypy x.py
x.py:3: error: Argument 1 to "append" of "list" has incompatible type "int"; expected "str"
Found 1 error in 1 file (checked 1 source file)
mypy -V
mypy 0.942
python -V
Python 3.10.0b2
Python 3.10.0b2`
Oh right, that's different from what I'm seeing here. I've got mypy version 0.812 though.
What should pylint do?
I think we should defer this to type checkers such as mypy
. We really struggle with inferring control flow in python files ourselves and I think we shouldn't try re-inventing the wheel.
If we ever have less than 10 issues open we could obviously revisit this, but I think for now there are pressing matters 😄
If we ever have less than 10 issues open
:)
I'm closing as out of scope for pylint for now, mypy is already doing type checking.
Current problem
I have the following file:
python blithely runs it, but neither pylint nor mypy actually catch the problem. mypy will complain about the above if we add a type annotation, but Python of course does not care.
Desired solution
I consider it bad style to put objects of differing types in lists, and I think a linter should warn of this kind of thing.
I would expect a message like
W1234: appending object of type "int" to list also containing objects of type "str"
The same goes for the keys of a dictionary and the values of a dictionary.
What do you think?
Additional context
Usually, when we consume iterables, it's to yield all objects of type Foo, so that we can call
foo.bar()
. We wouldn't want that kind of thing to throw a ThingNotFound exception at runtime.