Skip to content

Is this repo using mypy correctly? #2502

Closed

Description

@cclauss

@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?

Activity

  1. dhruvmanila commented on Sep 28, 2020

    @dhruvmanila
    Member

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

  2. dhruvmanila commented on Sep 28, 2020

    @dhruvmanila
    Member

    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).

  3. dhruvmanila commented on Sep 28, 2020

    @dhruvmanila
    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) 😱

  4. cclauss commented on Sep 28, 2020

    @cclauss
    MemberAuthor

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions