-
-
Notifications
You must be signed in to change notification settings - Fork 164
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
Add mypy config; run mypy in CI #286
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: mypy | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
pull_request: | ||
workflow_dispatch: | ||
|
||
permissions: | ||
contents: read | ||
|
||
env: | ||
FORCE_COLOR: 1 | ||
TERM: xterm-256color # needed for FORCE_COLOR to work on mypy on Ubuntu, see https://github.com/python/mypy/issues/13817 | ||
|
||
jobs: | ||
mypy: | ||
name: Check code with mypy | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-python@v4 | ||
with: | ||
cache: "pip" | ||
cache-dependency-path: "pyproject.toml" | ||
python-version: "3.11" | ||
- run: pip install -e .[dev] | ||
- run: pip freeze --all | ||
- run: mypy |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,6 +68,8 @@ dependencies = [ | |
[project.optional-dependencies] | ||
dev = [ | ||
'tox', | ||
'mypy==1.2.0', | ||
'tomli', # Needed even on 3.11+ for typechecking with mypy | ||
] | ||
|
||
[project.scripts] | ||
|
@@ -81,3 +83,23 @@ find = {} # Scanning implicit namespaces is active by default | |
|
||
[tool.setuptools.dynamic] | ||
version = {attr = "pyperformance.__version__"} | ||
|
||
[tool.mypy] | ||
python_version = "3.7" | ||
pretty = true | ||
enable_error_code = "ignore-without-code" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This means that mypy will emit an error if you do a bare |
||
disallow_any_generics = true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This means that mypy will forbid using, for example, |
||
warn_redundant_casts = true | ||
warn_unused_ignores = true | ||
warn_unused_configs = true | ||
files = [ | ||
'pyperformance/', | ||
] | ||
exclude = [ | ||
'pyperformance/data-files/', | ||
'pyperformance/tests/' | ||
] | ||
|
||
[[tool.mypy.overrides]] | ||
module = "pyperf" | ||
ignore_missing_imports = true | ||
Comment on lines
+104
to
+106
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pyperf doesn't have type annotations, so without this section, mypy would emit an error at every location pyperf was imported, which was quite annoying. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's generally a good idea to run mypy on the lowest Python version you support; this means it will flag if you accidentally use a feature that only exists in a newer Python version