Skip to content
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

Configure mypy #1243

Merged
merged 1 commit into from
Aug 18, 2022
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
9 changes: 0 additions & 9 deletions mypy.ini

This file was deleted.

22 changes: 22 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,25 @@ line_length = 100
force_sort_within_sections = true
# Combines "as" imports on the same line
combine_as_imports = true

[tool.mypy]
ignore_missing_imports = true
show_error_codes = true
disable_error_code = ["attr-defined", "var-annotated"]
Copy link
Member Author

Choose a reason for hiding this comment

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

These two error cases produced a lot of type errors, many of which were incorrect because of django typing stubs not working. I've disabled them for now, and if django typing stubs ever get integrated with django-configurations properly, we can re-enable them.

follow_imports = "skip" # Don't follow imports into other files. This should be removed once all type errors have been resolved.
exclude = [
"^dandiapi/api/admin.py",
"^dandiapi/api/mail.py",
"^dandiapi/api/tests/",
"^dandiapi/api/management/",
"^dandiapi/api/migrations/",
"^dandiapi/api/models/",
"^dandiapi/api/tasks/",
"^dandiapi/api/views/",
]
Comment on lines +20 to +29
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 now, I've excluded all files and directories that have type errors. I'll make follow up PRs where I fix the type errors in each of these and remove the corresponding entry from exclude.


# Re-enable these when https://github.com/typeddjango/django-stubs/issues/417 is fixed.
# plugins = ["mypy_django_plugin.main", "mypy_drf_plugin.main"]

# [tool.django-stubs]
# django_settings_module = "dandiapi.settings"
Comment on lines +31 to +35
Copy link
Member Author

Choose a reason for hiding this comment

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

Since we are using django-configurations (well, technically composed-configuration does, not dandi), there's some additional considerations for running these django plugins. There's an open issue to support it typeddjango/django-stubs#417, but it hasn't been implemented yet

Copy link
Collaborator

@brianhelba brianhelba Aug 15, 2022

Choose a reason for hiding this comment

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

DANDI does use django-configurations directly. That's why things like this: https://github.com/dandi/dandi-archive/blob/master/manage.py#L14 are necessary.

I agree that due to the lack of proper support, it's safer to disable these plugins for now.

3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@
'ipython',
'tox',
'boto3-stubs[s3]',
'django-stubs',
'djangorestframework-stubs',
'types-setuptools',
'memray',
],
'test': [
Expand Down
9 changes: 4 additions & 5 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[tox]
envlist =
lint,
type,
test,
check-migrations,

Expand All @@ -19,14 +20,12 @@ commands =
flake8 --config=tox.ini {posargs:.}

[testenv:type]
skipsdist = true
skip_install = true
deps =
mypy
django-stubs
djangorestframework-stubs
extras =
mvandenburgh marked this conversation as resolved.
Show resolved Hide resolved
dev
commands =
mypy {posargs:.}
mypy {posargs:dandiapi/}

[testenv:format]
skipsdist = true
Expand Down