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

Enable using mypy manually #7081

Merged
merged 22 commits into from
Aug 7, 2024
Merged

Enable using mypy manually #7081

merged 22 commits into from
Aug 7, 2024

Conversation

MarcSkovMadsen
Copy link
Collaborator

@MarcSkovMadsen MarcSkovMadsen commented Aug 6, 2024

In #7079, @gandhis1 contributes a typing improvement. In order to be able to review this PR I would like to run mypy.

This PR configures the project in such a way that you can

  • run pip install -e .[mypy] to install the mypy dependencies
  • run mypy path/to/file.py to check a specific file.

It removes the errors raised about missing stubs and dependencies that do not support typing.

Copy link

codecov bot commented Aug 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.21%. Comparing base (ad94551) to head (0b72a5a).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7081      +/-   ##
==========================================
- Coverage   82.22%   82.21%   -0.02%     
==========================================
  Files         326      326              
  Lines       48536    48536              
==========================================
- Hits        39908    39903       -5     
- Misses       8628     8633       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@hoxbro hoxbro self-requested a review August 6, 2024 06:40
@hoxbro hoxbro force-pushed the enhancement/enable-manual-mypy branch from d9effd6 to 7150ff4 Compare August 6, 2024 08:16
@hoxbro
Copy link
Member

hoxbro commented Aug 6, 2024

I pushed some changes so we can see the result of type checking in the CI. I have set the CI to never fail, but this should be removed at some point.

pyproject.toml Outdated Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
.github/workflows/test.yaml Outdated Show resolved Hide resolved
.github/workflows/test.yaml Outdated Show resolved Hide resolved
pixi.toml Outdated Show resolved Hide resolved
Copy link
Contributor

@gandhis1 gandhis1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this works, however I think what you choose to run depends on what you are looking to do. My original issue was concerned primarily with the public API, and to run Mypy on the files changed would also be checking elements of the private API and library internals.

Ideally, you would want to run Mypy on panel itself and check for / catch issues / validate annotations, but that would expose a larger number of errors to fix.

If we want to check the public API, I think the best thing would be to run mypy in strict mode on the examples folder, and when all the issues are fixed, adding it to the CI as well.

pixi.toml Show resolved Hide resolved
namespace_packages = true
explicit_package_bases = true
mypy_path = ""
exclude = []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran Mypy in the same way you were @MarcSkovMadsen and I got a bunch of additional errors on unrelated files. At least for now, maybe it's worth turning off the unrelated file errors?

Suggested change
exclude = []
exclude = []
follow_imports = "silent"

From https://mypy.readthedocs.io/en/stable/running_mypy.html#following-imports:

If you are starting a new codebase and plan on using type hints from the start, we recommend you use either --follow-imports=normal (the default) or --follow-imports=error. Either option will help make sure you are not skipping checking any part of your codebase by accident.

If you are planning on adding type hints to a large, existing code base, we recommend you start by trying to make your entire codebase (including files that do not use type hints) pass under --follow-imports=normal. This is usually not too difficult to do: mypy is designed to report as few error messages as possible when it is looking at unannotated code.

Only if doing this is intractable, we recommend passing mypy just the files you want to type check and use --follow-imports=silent. Even if mypy is unable to perfectly type check a file, it can still glean some useful information by parsing it (for example, understanding what methods a given object has). See Using mypy with an existing codebase for more recommendations.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should change it with the argument that what we want to check in the pipeline is everything as that is the end goal for the Panel project to have no issues whether internal facing or external facing.

I believe for "the current effort" which is focused on outward facing api we should add the relevant settings via flags manually when running mypy manually. Makes sense?

panel/io/cache.py Outdated Show resolved Hide resolved
pixi.toml Show resolved Hide resolved
Co-authored-by: Simon Høxbro Hansen <[email protected]>
Copy link
Contributor

@gandhis1 gandhis1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@philippjfr philippjfr merged commit 1083ed2 into main Aug 7, 2024
16 checks passed
@philippjfr philippjfr deleted the enhancement/enable-manual-mypy branch August 7, 2024 14:03
@philippjfr philippjfr modified the milestones: next, v1.5.0 Aug 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants