Skip to content

Commit c165413

Browse files
author
Julian Dehm
committed
add mypy as static type checker
1 parent 7f60973 commit c165413

File tree

6 files changed

+35
-0
lines changed

6 files changed

+35
-0
lines changed

.github/workflows/django.yml

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ jobs:
8888
isort --diff -c meinberlin tests
8989
python manage.py makemigrations --dry-run --check --noinput
9090
flake8 meinberlin tests --exclude migrations,settings
91+
mypy -p meinberlin tests
9192
- name: Coveralls
9293
env:
9394
GITHUB_TOKEN: ${{ secrets.COV }}

.mypy.ini

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[mypy]
2+
warn_return_any = False
3+
warn_unused_configs = True
4+
disable_error_code = import-untyped
5+
exclude = settings/|migrations/
6+
7+
[mypy-meinberlin.config.settings.*]
8+
follow_imports = skip
9+
10+

Makefile

+2
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ lint:
177177
EXIT_STATUS=0; \
178178
$(VIRTUAL_ENV)/bin/isort --diff -c $(SOURCE_DIRS) || EXIT_STATUS=$$?; \
179179
$(VIRTUAL_ENV)/bin/flake8 $(SOURCE_DIRS) --exclude migrations,settings || EXIT_STATUS=$$?; \
180+
$(VIRTUAL_ENV)/bin/mypy -p $(SOURCE_DIRS) || EXIT_STATUS=$$?; \
180181
npm run lint || EXIT_STATUS=$$?; \
181182
$(VIRTUAL_ENV)/bin/python manage.py makemigrations --dry-run --check --noinput || EXIT_STATUS=$$?; \
182183
exit $${EXIT_STATUS}
@@ -213,6 +214,7 @@ lint-python-files:
213214
$(VIRTUAL_ENV)/bin/black $(ARGUMENTS) || EXIT_STATUS=$$?; \
214215
$(VIRTUAL_ENV)/bin/isort $(ARGUMENTS) --filter-files || EXIT_STATUS=$$?; \
215216
$(VIRTUAL_ENV)/bin/flake8 $(ARGUMENTS) || EXIT_STATUS=$$?; \
217+
$(VIRTUAL_ENV)/bin/mypy -p $(ARGUMENTS) || EXIT_STATUS=$$?; \
216218
exit $${EXIT_STATUS}
217219

218220
.PHONY: po

changelog/_1113.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### Added
2+
3+
- add mypy static type checker

docs/linting.md

+18
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,24 @@ make lint-python-files meinberlin
8888

8989
For details on black see https://github.com/PyCQA/flake8
9090

91+
#### Mypy
92+
93+
We use mypy for static type checking of all our python code. It is
94+
run as part of the commit hook and checks all staged code. It can also be
95+
invoked manually as part of the`lint-python-files` command if you want to lint
96+
a specific file or folder or as part of the `lint` command to lint all files:
97+
98+
```
99+
# lint all python files
100+
make lint
101+
# lint specific python file or folder
102+
make lint-python-files <path>
103+
# example for linting all python files for mb
104+
make lint-python-files meinberlin
105+
```
106+
107+
For details on black see https://mypy-lang.org/
108+
91109
### JS / CSS
92110

93111
#### Eslint

requirements/dev.txt

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Faker==23.3.0
77
flake8==7.0.0
88
freezegun==1.4.0
99
isort==5.13.2
10+
mypy==1.11.0
1011
psycopg[binary]==3.1.18
1112
pytest==8.2.1
1213
pytest-cov==4.1.0

0 commit comments

Comments
 (0)