Skip to content

Commit

Permalink
add mypy as static type checker
Browse files Browse the repository at this point in the history
  • Loading branch information
goapunk committed Jul 23, 2024
1 parent 7f60973 commit c165413
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/django.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ jobs:
isort --diff -c meinberlin tests
python manage.py makemigrations --dry-run --check --noinput
flake8 meinberlin tests --exclude migrations,settings
mypy -p meinberlin tests
- name: Coveralls
env:
GITHUB_TOKEN: ${{ secrets.COV }}
Expand Down
10 changes: 10 additions & 0 deletions .mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[mypy]
warn_return_any = False
warn_unused_configs = True
disable_error_code = import-untyped
exclude = settings/|migrations/

[mypy-meinberlin.config.settings.*]
follow_imports = skip


2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ lint:
EXIT_STATUS=0; \
$(VIRTUAL_ENV)/bin/isort --diff -c $(SOURCE_DIRS) || EXIT_STATUS=$$?; \
$(VIRTUAL_ENV)/bin/flake8 $(SOURCE_DIRS) --exclude migrations,settings || EXIT_STATUS=$$?; \
$(VIRTUAL_ENV)/bin/mypy -p $(SOURCE_DIRS) || EXIT_STATUS=$$?; \
npm run lint || EXIT_STATUS=$$?; \
$(VIRTUAL_ENV)/bin/python manage.py makemigrations --dry-run --check --noinput || EXIT_STATUS=$$?; \
exit $${EXIT_STATUS}
Expand Down Expand Up @@ -213,6 +214,7 @@ lint-python-files:
$(VIRTUAL_ENV)/bin/black $(ARGUMENTS) || EXIT_STATUS=$$?; \
$(VIRTUAL_ENV)/bin/isort $(ARGUMENTS) --filter-files || EXIT_STATUS=$$?; \
$(VIRTUAL_ENV)/bin/flake8 $(ARGUMENTS) || EXIT_STATUS=$$?; \
$(VIRTUAL_ENV)/bin/mypy -p $(ARGUMENTS) || EXIT_STATUS=$$?; \
exit $${EXIT_STATUS}

.PHONY: po
Expand Down
3 changes: 3 additions & 0 deletions changelog/_1113.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Added

- add mypy static type checker
18 changes: 18 additions & 0 deletions docs/linting.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,24 @@ make lint-python-files meinberlin

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

#### Mypy

We use mypy for static type checking of all our python code. It is
run as part of the commit hook and checks all staged code. It can also be
invoked manually as part of the`lint-python-files` command if you want to lint
a specific file or folder or as part of the `lint` command to lint all files:

```
# lint all python files
make lint
# lint specific python file or folder
make lint-python-files <path>
# example for linting all python files for mb
make lint-python-files meinberlin
```

For details on black see https://mypy-lang.org/

### JS / CSS

#### Eslint
Expand Down
1 change: 1 addition & 0 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Faker==23.3.0
flake8==7.0.0
freezegun==1.4.0
isort==5.13.2
mypy==1.11.0
psycopg[binary]==3.1.18
pytest==8.2.1
pytest-cov==4.1.0
Expand Down

0 comments on commit c165413

Please sign in to comment.