I'm trying to type-check the latest revision of my code and get inconsistent results using the ALE plugin in vim and mypy
on the command line.
Update: After the comments from @aaron below, I checked out the code on a different machine, and it works as expected: I get more errors there, than on my main development machine. So ALE inside vim gives me the same results as the process on another machine. And I don't understand why.
Both should give me the same, but I noticed that ALE gives me more results than the command line. And I wonder what I am doing wrong with the CLI invocation of mypy
.
To set up and environment to reproduce the behaviour I am experiencing (ALE is not required):
4fb26c4e5b
python3 -m venv env
./env/bin/pip install -e .
./env/bin/pip install mypy
Now, using this environment, type-checking the directory puresnmp
yields the following:
$ ./env/bin/mypy puresnmp
puresnmp/aio/api/raw.py:505: error: Type signature has too few arguments
puresnmp/api/pythonic.py:239: error: Type signature has too few arguments
puresnmp/api/raw.py:490: error: Type signature has too few arguments
puresnmp/test/asyncmock.py:18: error: 'yield' in async function
Found 4 errors in 4 files (checked 38 source files)
Using either ./env/bin/mypy puresnmp/**/*.py
or ./env/bin/mypy -p puresnmp
yields the same report as above.
However, when specifying a file explicitly, I get way more errors (which happen to correspond to the ALE errors):
$ ./env/bin/mypy puresnmp/api/pythonic.py
puresnmp/x690/types.pyi:58: error: Return type "Union[Null, UnknownType]" of "from_bytes" incompatible with return type "Type[bytes]" in supertype "Type"
puresnmp/transport.py:83: error: Argument 1 to "Timeout" has incompatible type "str"; expected "int"
puresnmp/pdu.py:178: error: Argument 2 to "Sequence" has incompatible type "Union[str, bytes, int, datetime, timedelta, None]"; expected "Type[Any]"
puresnmp/pdu.py:217: error: On Python 3 '%s' % b'abc' produces "b'abc'"; use %r if this is a desired behavior
puresnmp/pdu.py:253: error: Argument 2 to "VarBind" has incompatible type "Null"; expected "Union[str, bytes, int, datetime, timedelta, None]"
puresnmp/pdu.py:316: error: Argument 2 to "VarBind" has incompatible type "Null"; expected "Union[str, bytes, int, datetime, timedelta, None]"
puresnmp/pdu.py:320: error: Argument 2 to "Sequence" has incompatible type "Union[str, bytes, int, datetime, timedelta, None]"; expected "Type[Any]"
puresnmp/pdu.py:365: error: On Python 3 '%s' % b'abc' produces "b'abc'"; use %r if this is a desired behavior
puresnmp/api/raw.py:104: error: Incompatible return value type (got "List[Union[ObjectIdentifier, Union[str, bytes, int, datetime, timedelta, None]]]", expected "List[Type[Union[str, bytes, int, datetime, timedelta, None]]]")
puresnmp/api/raw.py:160: error: Argument 1 to "VarBind" has incompatible type "Union[ObjectIdentifier, Union[str, bytes, int, datetime, timedelta, None]]"; expected "Union[ObjectIdentifier, str]"
puresnmp/api/raw.py:160: error: Argument 2 to "VarBind" has incompatible type "Union[ObjectIdentifier, Union[str, bytes, int, datetime, timedelta, None]]"; expected "Union[str, bytes, int, datetime, timedelta, None]"
puresnmp/api/raw.py:164: error: Unsupported left operand type for < ("ObjectIdentifier")
puresnmp/api/raw.py:317: error: Argument 2 to "VarBind" has incompatible type "Type[Union[str, bytes, int, datetime, timedelta, None]]"; expected "Union[str, bytes, int, datetime, timedelta, None]"
puresnmp/api/raw.py:336: error: Incompatible return value type (got "Dict[str, Union[ObjectIdentifier, Union[str, bytes, int, datetime, timedelta, None]]]", expected "Dict[str, Type[Union[str, bytes, int, datetime, timedelta, None]]]")
puresnmp/api/raw.py:460: error: Incompatible types in assignment (expression has type "Union[ObjectIdentifier, Union[str, bytes, int, datetime, timedelta, None]]", target has type "Type[Union[str, bytes, int, datetime, timedelta, None]]")
puresnmp/api/raw.py:490: error: Type signature has too few arguments
puresnmp/api/raw.py:566: error: Argument 1 to "len" has incompatible type "ObjectIdentifier"; expected "Sized"
puresnmp/api/raw.py:570: error: Argument 1 to "tablify" has incompatible type "List[VarBind]"; expected "Iterable[Tuple[Any, Any]]"
puresnmp/api/raw.py:587: error: Argument 1 to "len" has incompatible type "ObjectIdentifier"; expected "Sized"
puresnmp/api/pythonic.py:104: error: Item "str" of "Union[ObjectIdentifier, str, bytes, int, datetime, timedelta, None, Any]" has no attribute "pythonize"
puresnmp/api/pythonic.py:104: error: Item "bytes" of "Union[ObjectIdentifier, str, bytes, int, datetime, timedelta, None, Any]" has no attribute "pythonize"
puresnmp/api/pythonic.py:104: error: Item "int" of "Union[ObjectIdentifier, str, bytes, int, datetime, timedelta, None, Any]" has no attribute "pythonize"
puresnmp/api/pythonic.py:104: error: Item "datetime" of "Union[ObjectIdentifier, str, bytes, int, datetime, timedelta, None, Any]" has no attribute "pythonize"
puresnmp/api/pythonic.py:104: error: Item "timedelta" of "Union[ObjectIdentifier, str, bytes, int, datetime, timedelta, None, Any]" has no attribute "pythonize"
puresnmp/api/pythonic.py:104: error: Item "None" of "Union[ObjectIdentifier, str, bytes, int, datetime, timedelta, None, Any]" has no attribute "pythonize"
puresnmp/api/pythonic.py:154: error: Argument 1 to "VarBind" has incompatible type "Union[ObjectIdentifier, Union[str, bytes, int, datetime, timedelta, None]]"; expected "Union[ObjectIdentifier, str]"
puresnmp/api/pythonic.py:154: error: Item "str" of "Union[ObjectIdentifier, Union[str, bytes, int, datetime, timedelta, None]]" has no attribute "pythonize"
puresnmp/api/pythonic.py:154: error: Item "bytes" of "Union[ObjectIdentifier, Union[str, bytes, int, datetime, timedelta, None]]" has no attribute "pythonize"
puresnmp/api/pythonic.py:154: error: Item "int" of "Union[ObjectIdentifier, Union[str, bytes, int, datetime, timedelta, None]]" has no attribute "pythonize"
puresnmp/api/pythonic.py:154: error: Item "datetime" of "Union[ObjectIdentifier, Union[str, bytes, int, datetime, timedelta, None]]" has no attribute "pythonize"
puresnmp/api/pythonic.py:154: error: Item "timedelta" of "Union[ObjectIdentifier, Union[str, bytes, int, datetime, timedelta, None]]" has no attribute "pythonize"
puresnmp/api/pythonic.py:154: error: Item "object" of "Union[ObjectIdentifier, Union[str, bytes, int, datetime, timedelta, None]]" has no attribute "pythonize"
puresnmp/api/pythonic.py:169: error: Argument 1 to "VarBind" has incompatible type "Union[ObjectIdentifier, Union[str, bytes, int, datetime, timedelta, None]]"; expected "Union[ObjectIdentifier, str]"
puresnmp/api/pythonic.py:169: error: Item "str" of "Union[ObjectIdentifier, Union[str, bytes, int, datetime, timedelta, None]]" has no attribute "pythonize"
puresnmp/api/pythonic.py:169: error: Item "bytes" of "Union[ObjectIdentifier, Union[str, bytes, int, datetime, timedelta, None]]" has no attribute "pythonize"
puresnmp/api/pythonic.py:169: error: Item "int" of "Union[ObjectIdentifier, Union[str, bytes, int, datetime, timedelta, None]]" has no attribute "pythonize"
puresnmp/api/pythonic.py:169: error: Item "datetime" of "Union[ObjectIdentifier, Union[str, bytes, int, datetime, timedelta, None]]" has no attribute "pythonize"
puresnmp/api/pythonic.py:169: error: Item "timedelta" of "Union[ObjectIdentifier, Union[str, bytes, int, datetime, timedelta, None]]" has no attribute "pythonize"
puresnmp/api/pythonic.py:169: error: Item "object" of "Union[ObjectIdentifier, Union[str, bytes, int, datetime, timedelta, None]]" has no attribute "pythonize"
puresnmp/api/pythonic.py:185: error: Argument 1 to "VarBind" has incompatible type "Union[ObjectIdentifier, Union[str, bytes, int, datetime, timedelta, None]]"; expected "Union[ObjectIdentifier, str]"
puresnmp/api/pythonic.py:239: error: Type signature has too few arguments
puresnmp/api/pythonic.py:258: error: The return type of a generator function should be "Generator" or one of its supertypes
puresnmp/api/pythonic.py:272: error: Argument 1 to "len" has incompatible type "ObjectIdentifier"; expected "Sized"
puresnmp/api/pythonic.py:282: error: The return type of a generator function should be "Generator" or one of its supertypes
puresnmp/api/pythonic.py:296: error: Argument 1 to "len" has incompatible type "ObjectIdentifier"; expected "Sized"
Found 45 errors in 5 files (checked 1 source file)
How can this difference be explained?
And more importantly: How can I get all the errors without specifying each file manually?
I believe that by default when you pass a folder, for mypy
it means scan this package
. So it follows imports. (this case ./env/bin/mypy puresnmp
)
When you pass python files list as args - it scans the files list.
Check more details on the docs website https://mypy.readthedocs.io/en/stable/command_line.html#cmdoption-mypy-follow-imports
https://mypy.readthedocs.io/en/stable/running_mypy.html#following-imports
mypy
on all filesI think you should be able to run the utility on all the python files in a folder you can run it like ./env/bin/mypy $(find puresnmp -name "*.py")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With