Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

add a mypy pre-commit hook #26954

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

Merged
merged 1 commit into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions 17 .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,23 @@ repos:
- id: no-commit-to-branch #default is master and main
- id: trailing-whitespace
exclude_types: [svg]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.1.1
hooks:
- id: mypy
additional_dependencies: [
pandas-stubs,
types-pillow,
types-python-dateutil,
types-psutil,
types-docutils,
types-PyYAML]
args: [
"--config-file=pyproject.toml",
"lib/matplotlib"
]
files: lib/matplotlib #only run when files in lib/matplotlib are changed
pass_filenames: false
- repo: https://github.com/pycqa/flake8
rev: 6.0.0
hooks:
Expand Down
20 changes: 15 additions & 5 deletions 20 pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -207,15 +207,25 @@ convention = "numpy"
"galleries/users_explain/text/text_props.py" = ["E501"]

[tool.mypy]
ignore_missing_imports = true
enable_incomplete_feature = [
"Unpack",
]
exclude = [
#stubtest
".*/matplotlib/(sphinxext|backends|testing/jpl_units)",
".*/mpl_toolkits",
#mypy precommit
"galleries/",
"doc/",
"lib/matplotlib/backends/",
"lib/matplotlib/sphinxext",
"lib/matplotlib/testing/jpl_units",
"lib/mpl_toolkits/",
Comment on lines +220 to +223
Copy link
Member

Choose a reason for hiding this comment

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

these are included in the first two regex entry (which is a regex to allow the mypy -m matplotlib form which looks at installed version which is needed for stubtest.

Additionally, tests should be included, while we do not fully type hint it, it provides a set of code that was not a large burden to add minimal types to but helps to check more usage than stubs alone do.
I would not mind expanding this to galleries once type hints are more established (so not super soon), but there are complexities such as reused variables which change types, etc.

I'm not totally opposed to adding galleries and docs to this list for now, though when run as mypy lib/matplotlib they are not needed.

Copy link
Member Author

Choose a reason for hiding this comment

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

for reasons I don't understand, the regex is totally ignored when I run on my machine but the explicit listing isn't. I didn't remove the regex in case you need it for something else

#removing tests causes errors in backends
"lib/matplotlib/tests/",
# tinypages is used for testing the sphinx ext,
# stubtest will import and run, opening a figure if not excluded
".*/tinypages",
]
enable_incomplete_feature = [
"Unpack",
".*/tinypages"
]

[tool.rstcheck]
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.