-
Notifications
You must be signed in to change notification settings - Fork 220
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 for static type checking #2808
Changes from 27 commits
c1bd0be
594e07e
16da12b
fec7e8b
ebe7d50
85e7128
2310e7e
9dc8c98
dda26d4
97d3dbc
8b2a5b9
aed77ad
9fd5a04
fa44524
e62dcb6
ec25885
73c9863
4d31ce3
a7545ad
49e67d5
253a491
567bfb8
5e401c2
cd9d3ed
9bfe49a
f230b0d
0e657bd
30b45c1
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,53 @@ | ||
# Static type checks | ||
# | ||
# This workflow runs static type checks using mypy. | ||
# | ||
# It is run on every commit to the main and pull request branches. It is also | ||
# scheduled to run daily on the main branch. | ||
# | ||
name: Static Type Checks | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
# Schedule daily tests | ||
schedule: | ||
- cron: '0 0 * * *' | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} | ||
|
||
jobs: | ||
static_check: | ||
name: Static Type Check | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
# Checkout current git repository | ||
- name: Checkout | ||
uses: actions/[email protected] | ||
|
||
# Setup Python | ||
- name: Set up Python | ||
uses: actions/[email protected] | ||
with: | ||
python-version: '3.12' | ||
|
||
- name: Install packages | ||
run: | | ||
# Need to install four groups of packages: | ||
# 1. required packages | ||
# 2. optional packages | ||
# 3. type checker and stub packages | ||
# 4. other packages that are used somewhere in PyGMT | ||
python -m pip install \ | ||
numpy pandas xarray netcdf4 packaging \ | ||
contextily geopandas ipython rioxarray \ | ||
mypy pandas-stubs \ | ||
matplotlib pytest | ||
python -m pip list | ||
|
||
- name: Static type check | ||
run: make typecheck |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ MANIFEST | |
.coverage | ||
coverage.xml | ||
htmlcov/ | ||
.mypy_cache/ | ||
.pytest_cache/ | ||
.ruff_cache/ | ||
results/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
""" | ||
Internal function to load GMT remote datasets. | ||
""" | ||
from typing import NamedTuple | ||
from typing import NamedTuple, Union | ||
|
||
from pygmt.exceptions import GMTInvalidInput | ||
from pygmt.helpers import kwargs_to_strings | ||
|
@@ -58,7 +58,7 @@ class GMTRemoteDataset(NamedTuple): | |
title: str | ||
name: str | ||
long_name: str | ||
units: str | ||
units: Union[str, None] | ||
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. Fix the following error:
|
||
resolutions: dict[str, Resolution] | ||
extra_attributes: dict | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,6 +86,10 @@ make-summary-multi-line = true | |
wrap-summaries = 79 | ||
wrap-descriptions = 79 | ||
|
||
[tool.mypy] | ||
exclude = ["pygmt/tests/"] | ||
ignore_missing_imports = 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. Some packages like geopandas don't provide type hints and mypy reports following errors:
Ignore these errors following https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports. |
||
|
||
[tool.ruff] | ||
line-length = 88 # E501 (line-too-long) | ||
show-source = true | ||
|
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.
Maybe move this under the
# Dev dependencies (style checks)
section?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.
I prefer to keep them in a separate section.