TheAlgorithms / Python

All Algorithms implemented in Python
https://the-algorithms.com/
MIT License
182.12k stars 44k forks source link

How to handle mypy implementation errors? #4256

Closed algobytewise closed 3 years ago

algobytewise commented 3 years ago

Many of the current errors when running the command mypy . are implementation errors of the following form: scheduling\shortest_job_first.py:8: error: Cannot find implementation or library stub for module named 'pandas'. These errors can be fixed by adding the comment # type: ignore at the end of the line, thereby telling mypy to ignore them, for example import pandas as pd # type: ignore. But all these errors can be silenced by running the command mypy . --ignore-missing-imports, avoiding the need to fix them one by one. So the question is: should these errors be fixed for each file or can they be ignored since the check to be implemented will silence them anyways? Without the ignore-parameter, we have: Found 586 errors in 189 files. With it, we have: Found 477 errors in 132 files.

algobytewise commented 3 years ago

The mypy documentation of this issue can be found here: https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports

algobytewise commented 3 years ago

@cclauss just pointed out to me that the automatic checks already include the ignore-missing-imports parameter, so the implementation errors don't need to be fixed. See https://github.com/TheAlgorithms/Python/blob/master/.pre-commit-config.yaml#L33

cclauss commented 3 years ago

Those tests are commented out so it would be awesome if we could put the fixes in place so that we can automatically run mypy -ignore-missing-imports . on every pull request.

cclauss commented 3 years ago

% mypy --ignore-missing-imports . > files.txt % python3

>>> with open("files.txt") as in_file:
...     print("\n* [ ] ".join(sorted(set(line.split(":")[0] for line in in_file))))
...
cclauss commented 3 years ago

So... We can successfully run

% mypy --ignore-missing-imports arithmetic_analysis backtracking bit_manipulation blockchain boolean_algebra cellular_automata computer_vision digital_image_processing fuzzy_logic genetic_algorithm geodesy knapsack networking_flow scheduling sorts Success: no issues found in 138 source files

cclauss commented 3 years ago

4274 works better than #4272

cclauss commented 3 years ago

Let's focus the mypy discussions on #4052