Skip to content
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

Is this repo using mypy correctly? #2502

Closed
cclauss opened this issue Sep 28, 2020 · 4 comments · Fixed by #2503
Closed

Is this repo using mypy correctly? #2502

cclauss opened this issue Sep 28, 2020 · 4 comments · Fixed by #2503

Comments

@cclauss
Copy link
Member

cclauss commented Sep 28, 2020

@dhruvmanila Is mypy running properly in our Travis CI runs? I believe that I made a mistake in #2464 which mypy is complaining about but it only seems to be raising issues in the maths subdirectory. Are we doing something wrong here?

@dhruvmanila
Copy link
Member

Let me take a look at it and I'll get back to you.

@dhruvmanila
Copy link
Member

dhruvmanila commented Sep 28, 2020

I see the problem.
As mentioned in #2463 (comment), mypy ignores all the directories which don't contain the __init__.py file, and as the maths subdirectory contains the __init__.py file, mypy is only complaining about the errors in that specific directory. I will put the highlights here:

Updated metrics

There's already an open issue about it (Why do we need __init__.py files?): python/mypy#6385
Here's Guido van Rossum explaining what is going on: python/mypy#6385 (comment)

Out of 124 directories only 62 contains the __init__.py file and most of them are the project_euler/.. directories.

It's checking only for 116 files while there are around 736 files with extension py with around 124 directories according to:

$ fd -t f -e py --full-path Python/ | wc -l        # find files with extension py and count the lines
       736

$ fd -t d --full-path Python/ | wc -l                 # find directories and count the lines
       124

By running a simple bash script, I found that __init__.py exists only in these directories, but mypy will stop recursing into the subdirectories if it doesn't find __init__.py file in the parent directory. What I mean is it looks for Python files in ./Python/maths/ but not in ./Python/data_structures/stacks/ as there is no init file in data_structures directory.

__init__.py exists in ./Python/data_structures/hashing/number_theory/
__init__.py exists in ./Python/data_structures/linked_list/
__init__.py exists in ./Python/data_structures/stacks/
__init__.py exists in ./Python/digital_image_processing/
__init__.py exists in ./Python/digital_image_processing/dithering/
__init__.py exists in ./Python/digital_image_processing/edge_detection/
__init__.py exists in ./Python/digital_image_processing/filters/
__init__.py exists in ./Python/digital_image_processing/resize/
__init__.py exists in ./Python/digital_image_processing/rotation/
__init__.py exists in ./Python/maths/
__init__.py exists in ./Python/project_euler/problem_01/

...

And all the subdirectories of project_euler/..

For now, the only solution is to add the __init__.py files in all the directories and subdirectories (which can be easily done using a simple bash script).

@dhruvmanila
Copy link
Member

I added the file in their respective directories and found this after running mypy --ignore-missing-imports Python/

Found 507 errors in 129 files (checked 736 source files) 😱

@cclauss
Copy link
Member Author

cclauss commented Sep 28, 2020

OK. Can you please submit a PR that ONLY adds all these __init__.py files (that way we can revert the commit in the future if mypy comes up with a more rational approach). After we land that PR, we can create another PR that fixes the mypy issues and removes the || true. Thanks for your research on this topic.

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

Successfully merging a pull request may close this issue.

2 participants