Skip to content

How to handle mypy implementation errors? #4256

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
algobytewise opened this issue Mar 5, 2021 · 7 comments
Closed

How to handle mypy implementation errors? #4256

algobytewise opened this issue Mar 5, 2021 · 7 comments

Comments

@algobytewise
Copy link
Contributor

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
Copy link
Contributor Author

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

@algobytewise
Copy link
Contributor Author

@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
Copy link
Member

cclauss commented Mar 19, 2021

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
Copy link
Member

cclauss commented Mar 19, 2021

% 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))))
...
  • ciphers/cryptomath_module.py
  • ciphers/decrypt_caesar_with_chi_squared.py
  • ciphers/diffie.py
  • ciphers/diffie_hellman.py
  • ciphers/elgamal_key_generator.py
  • ciphers/enigma_machine2.py
  • ciphers/hill_cipher.py
  • ciphers/mixed_keyword_cypher.py
  • ciphers/onepad_cipher.py
  • ciphers/playfair_cipher.py
  • ciphers/porta_cipher.py
  • ciphers/rail_fence_cipher.py
  • ciphers/rsa_cipher.py
  • ciphers/rsa_factorization.py
  • ciphers/shuffled_shift_cipher.py
  • ciphers/trafid_cipher.py
  • ciphers/xor_cipher.py
  • compression/lempel_ziv.py
  • conversions/decimal_to_binary.py
  • conversions/decimal_to_octal.py
  • conversions/prefix_conversions.py
  • data_structures/binary_tree/binary_search_tree.py
  • data_structures/binary_tree/lowest_common_ancestor.py
  • data_structures/binary_tree/merge_two_binary_trees.py
  • data_structures/binary_tree/non_recursive_segment_tree.py
  • data_structures/binary_tree/red_black_tree.py
  • data_structures/heap/randomized_heap.py
  • data_structures/heap/skew_heap.py
  • data_structures/linked_list/init.py
  • data_structures/linked_list/circular_linked_list.py
  • data_structures/linked_list/has_loop.py
  • data_structures/linked_list/middle_element_of_linked_list.py
  • data_structures/linked_list/skip_list.py
  • data_structures/queue/linked_queue.py
  • data_structures/stacks/evaluate_postfix_notations.py
  • data_structures/stacks/linked_stack.py
  • data_structures/stacks/next_greater_element.py
  • data_structures/stacks/stack.py
  • data_structures/trie/trie.py
  • divide_and_conquer/max_difference_pair.py
  • divide_and_conquer/strassen_matrix_multiplication.py
  • dynamic_programming/fractional_knapsack_2.py
  • dynamic_programming/knapsack.py
  • dynamic_programming/longest_increasing_subsequence.py
  • electronics/electric_power.py
  • electronics/ohms_law.py
  • file_transfer/receive_file.py
  • file_transfer/send_file.py
  • graphs/basic_graphs.py
  • graphs/bellman_ford.py
  • graphs/bfs_shortest_path.py
  • graphs/bfs_zero_one_shortest_path.py
  • graphs/bidirectional_a_star.py
  • graphs/bidirectional_breadth_first_search.py
  • graphs/breadth_first_search.py
  • graphs/breadth_first_search_shortest_path.py
  • graphs/depth_first_search.py
  • graphs/even_tree.py
  • graphs/frequent_pattern_graph_miner.py
  • graphs/gale_shapley_bigraph.py
  • graphs/graph_list.py
  • graphs/greedy_best_first.py
  • graphs/minimum_spanning_tree_kruskal.py
  • graphs/minimum_spanning_tree_kruskal2.py
  • graphs/minimum_spanning_tree_prims2.py
  • graphs/multi_heuristic_astar.py
  • graphs/scc_kosaraju.py
  • graphs/strongly_connected_components.py
  • hashes/adler32.py
  • hashes/chaos_machine.py
  • hashes/enigma_machine.py
  • hashes/sdbm.py
  • linear_algebra/src/polynom_for_points.py
  • linear_algebra/src/power_iteration.py
  • machine_learning/forecasting/run.py
  • machine_learning/word_frequency_functions.py
  • maths/series/geometric_series.py
  • maths/series/harmonic_series.py
  • maths/series/p_series.py
  • matrix/matrix_operation.py
  • neural_network/perceptron.py
  • other/davis–putnam–logemann–loveland.py
  • other/graham_scan.py
  • other/least_recently_used.py
  • other/lfu_cache.py
  • other/lru_cache.py
  • other/markov_chain.py
  • other/scoring_algorithm.py
  • other/triplet_sum.py
  • other/two_sum.py
  • other/word_patterns.py
  • project_euler/problem_003/sol1.py
  • project_euler/problem_003/sol3.py
  • project_euler/problem_007/sol2.py
  • project_euler/problem_008/sol2.py
  • project_euler/problem_009/sol1.py
  • project_euler/problem_014/sol1.py
  • project_euler/problem_025/sol2.py
  • project_euler/problem_026/sol1.py
  • project_euler/problem_037/sol1.py
  • project_euler/problem_044/sol1.py
  • project_euler/problem_046/sol1.py
  • project_euler/problem_051/sol1.py
  • project_euler/problem_074/sol2.py
  • project_euler/problem_080/sol1.py
  • project_euler/problem_099/sol1.py
  • project_euler/problem_101/sol1.py
  • project_euler/problem_188/sol1.py
  • project_euler/problem_191/sol1.py
  • project_euler/problem_207/sol1.py
  • project_euler/problem_551/sol1.py
  • quantum/ripple_adder_classic.py
  • scripts/validate_filenames.py
  • scripts/validate_solutions.py
  • searches/simulated_annealing.py
  • searches/ternary_search.py
  • strings/aho_corasick.py
  • strings/can_string_be_rearranged_as_palindrome.py
  • strings/levenshtein_distance.py
  • strings/manacher.py
  • strings/min_cost_string_conversion.py
  • strings/word_occurrence.py
  • traversals/binary_tree_traversals.py
  • web_programming/currency_converter.py
  • web_programming/emails_from_url.py

@cclauss
Copy link
Member

cclauss commented Mar 19, 2021

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
Copy link
Member

cclauss commented Mar 19, 2021

#4274 works better than #4272

@cclauss
Copy link
Member

cclauss commented Mar 19, 2021

Let's focus the mypy discussions on #4052

@cclauss cclauss closed this as completed Mar 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants