msherry / flycheck-pycheckers

Multiple syntax checker for Python in Emacs, using Flycheck
GNU General Public License v3.0
63 stars 23 forks source link

feat(mypy): Hint for files existing outside project directory #50

Open captain-kark opened 4 years ago

captain-kark commented 4 years ago

I am working in a project where all tests are placed in a sibling directory next to the main project's source root.

cd ./some_project
tree
├── Makefile
├── README.md
├── some_project
│   ├── __init__.py
│   └── __main__.py
├── mypy.ini
├── pytest.ini
├── requirements-frozen.txt
├── requirements.txt
└── tests
    ├── conftest.py
    └── unit_tests
        ├── some_feature
        │   ├── test_foo.py
        │   └── test_bar.py
        └── test_baz.py

If you include a mypy_path in mypy.ini pointing to your current project, when combined with find_project_root, a check can be made to use your project's existing mypy type definitions while editing code in the tests directory.

When editing code that matches a directory that shares its base with a mypy_path, nothing is done since it is already in mypy's context.

captain-kark commented 4 years ago

As it stands, right now this pull request will only resolve any errors coming from mypy saying it can't find your module's type definitions in your current test file, but actual type checking isn't working. I'm investigating a couple of issues with my setup/project and determining which of the following could be causing issues with the behavior I'm seeing versus what I would expect:

I'll be making a some_project/lib/__init__.py module and repeat all of these steps, and next. If that doesn't work, I'll drop the __main__.py entirely and move everything out of __init__.py so that it only imports from sibling module definitions. If there still isn't any progress on getting type checking working in my tests, I'll look into either moving my tests into the module source directly, and later, seeing if there's any special edge cases needed when using mypy in a directory that's expected to host pytest runners.

Any of this ringing a bell for you? Any ideas what I might be doing wrong, or why I might be having issues getting mypy to return false positives like this?