[BUG] MyPy test failures on main
See original GitHub issueLooks like mypy is failing on the current main. I am not sure what changed / how this got into main unless it was just caused by a update to mypy itself.
Example: this PR which changed nothing about the code https://github.com/microsoft/graspologic/pull/908 Test output (unit-and-doc-test):
Run mypy ./graspologic
graspologic\match\qap.py:420: error: Argument "key" to "sorted" has incompatible type "Callable[[Union[Sequence[Sequence[Sequence[Sequence[Sequence[Any]]]]], _SupportsArray[dtype[Any]], Sequence[_SupportsArray[dtype[Any]]], Sequence[Sequence[_SupportsArray[dtype[Any]]]], Sequence[Sequence[Sequence[_SupportsArray[dtype[Any]]]]], Sequence[Sequence[Sequence[Sequence[_SupportsArray[dtype[Any]]]]]], complex, Sequence[Union[complex, str, bytes]], Sequence[Sequence[Union[complex, str, bytes]]], Sequence[Sequence[Sequence[Union[complex, str, bytes]]]], Sequence[Sequence[Sequence[Sequence[Union[complex, str, bytes]]]]]]], Union[Sequence[Sequence[Sequence[Sequence[Any]]]], Any, _SupportsArray[dtype[Any]], Sequence[_SupportsArray[dtype[Any]]], Sequence[Sequence[_SupportsArray[dtype[Any]]]], Sequence[Sequence[Sequence[_SupportsArray[dtype[Any]]]]], complex, Sequence[Union[complex, str, bytes]], Sequence[Sequence[Union[complex, str, bytes]]], Sequence[Sequence[Sequence[Union[complex, str, bytes]]]]]]"; expected "Callable[[Union[Sequence[Sequence[Sequence[Sequence[Sequence[Any]]]]], _SupportsArray[dtype[Any]], Sequence[_SupportsArray[dtype[Any]]], Sequence[Sequence[_SupportsArray[dtype[Any]]]], Sequence[Sequence[Sequence[_SupportsArray[dtype[Any]]]]], Sequence[Sequence[Sequence[Sequence[_SupportsArray[dtype[Any]]]]]], complex, Sequence[Union[complex, str, bytes]], Sequence[Sequence[Union[complex, str, bytes]]], Sequence[Sequence[Sequence[Union[complex, str, bytes]]]], Sequence[Sequence[Sequence[Sequence[Union[complex, str, bytes]]]]]]], Union[SupportsDunderLT, SupportsDunderGT]]"
graspologic\match\qap.py:420: error: Value of type "Union[Sequence[Sequence[Sequence[Sequence[Sequence[Any]]]]], _SupportsArray[dtype[Any]], Sequence[_SupportsArray[dtype[Any]]], Sequence[Sequence[_SupportsArray[dtype[Any]]]], Sequence[Sequence[Sequence[_SupportsArray[dtype[Any]]]]], Sequence[Sequence[Sequence[Sequence[_SupportsArray[dtype[Any]]]]]], complex, Sequence[Union[complex, str, bytes]], Sequence[Sequence[Union[complex, str, bytes]]], Sequence[Sequence[Sequence[Union[complex, str, bytes]]]], Sequence[Sequence[Sequence[Sequence[Union[complex, str, bytes]]]]]]" is not indexable
graspologic\match\qap.py:420: error: Incompatible return value type (got "Union[Sequence[Sequence[Sequence[Sequence[Any]]]], Any, _SupportsArray[dtype[Any]], Sequence[_SupportsArray[dtype[Any]]], Sequence[Sequence[_SupportsArray[dtype[Any]]]], Sequence[Sequence[Sequence[_SupportsArray[dtype[Any]]]]], complex, Sequence[Union[complex, str, bytes]], Sequence[Sequence[Union[complex, str, bytes]]], Sequence[Sequence[Sequence[Union[complex, str, bytes]]]]]", expected "Union[SupportsDunderLT, SupportsDunderGT]")
graspologic\match\qap.py:433: error: Item "int" of "Union[int, RandomState, Generator, None]" has no attribute "permutation"
graspologic\match\qap.py:433: error: Item "None" of "Union[int, RandomState, Generator, None]" has no attribute "permutation"
graspologic\match\qap.py:457: error: Item "int" of "Union[int, RandomState, Generator, None]" has no attribute "uniform"
graspologic\match\qap.py:457: error: Item "None" of "Union[int, RandomState, Generator, None]" has no attribute "uniform"
graspologic\cluster\autogmm.py:559: error: Incompatible types in assignment (expression has type "List[Optional[RandomState]]", variable has type "ndarray[Any, dtype[signedinteger[Any]]]")
graspologic\embed\base.py:439: error: <nothing> has no attribute "ndim"
graspologic\embed\base.py:441: error: <nothing> has no attribute "ndim"
graspologic\embed\base.py:444: error: <nothing> has no attribute "shape"
graspologic\embed\base.py:446: error: <nothing> has no attribute "shape"
graspologic\embed\base.py:449: error: Incompatible types in assignment (expression has type "Union[ndarray[Any, Any], Any]", variable has type "List[Union[ndarray[Any, Any], Any]]")
graspologic\embed\case.py:205: error: Incompatible types in assignment (expression has type "floating[Any]", variable has type "float")
Found 14 errors in 4 files (checked 79 source files)
Error: Process completed with exit code 1.
Side note: when I get the latest version of mypy and run it locally on main, I actually get
Found 393 errors in 55 files (checked 78 source files)
I wont post the whole traceback but these errors involve basically every module in the library. Many are private functions.
A few larger points for discussion:
- Would anyone be opposed to taking mypy out of unit-and-doc-test and putting it as it’s own check, much like black has its own code-format-check? It seems unnecessary to check on every os/version like we do for actual tests.
- Can someone explain to me what mypy gives us that beartype doesn’t? I know it is static and beartype is dynamic, right? but in practice what is this doing for us?
- If nothing, can we remove?
- What is our policy on mypy compatibility for legacy code that is private?
- any tips on getting mypy to tell me what the function is that is actually causing the error? --verbose did not do it for me.
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
tests failing on master (macOS Monterey / py 3.7) · Issue #12615
Tests pass. Actual Behavior. There's usually exactly one failure per run. On some rare occasions I've seen more than one failure, or no...
Read more >Common issues and solutions - mypy 0.991 documentation
Common issues and solutions#. This section has examples of cases when you need to update your code to use static typing, and ideas...
Read more >[BUG] MyPy test failures on main - Microsoft/Graspologic
Looks like mypy is failing on the current main. I am not sure what changed / how this got into main unless it...
Read more >Mypy: get rid of python bugs with static type-checking ! - Sicara
Mypy becomes a very useful tool for overcoming these difficulties, by locating typing mistakes and helping you fix them step by step. Pros...
Read more >Mypy Documentation - Read the Docs
Mypy is a static type checker for Python. Type checkers help ensure that you're using variables and functions in your code correctly.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Yes, because somewhere in our stack there’s a python method that does one thing if it is windows and another if it is a unix variant re: types, and it wasn’t found until later. And it was annoying to uncover. That’s why we’re doing it on all OSes (and versions, since apparently that’s a common-enough-pattern in Python to return different things depending on the Python version you’re on)
update - this is only happening on 3.7 and 3.8. 3.9 has another issue (see #910)