-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
INTERNAL ERROR when using mypy with pre-commit (all versions) #18579
Comments
What happens if you disable the plugins? And does pre-commit run -a fail? |
Disabling the plugins does work, and mypy no longer returns an error. Specifically, disabling the I updated |
If you run cc @sobolevn |
Actually no. It still works when running mypy directly.
At this point I made another change in
|
Sorry just to be explicit, I mean passing mypy a list of |
Does it happen without |
@A5rocks The issue still does not happen when passing specific files to mypy. The problem does happen with pre-commit, but then I run directly with the list of files and get:
So it is still limited only to pre-commit as far as I can tell. @sobolevn When I remove django-stubs, the error does not happen, even with pre-commit. It does seem to be tied specifically to pre-commit and specifically to django-stubs. For clarity, earlier post where I checked that: #18579 (comment) |
This is indeed likely specific to django-stubs, but has nothing to do with pre-commit. Full script: cd "$(mktemp -d)"
uv venv --python 3.12 && . ./.venv/bin/activate
uv pip install mypy django django-stubs
mkdir -p backend/bethpage
touch backend/bethpage/__init__.py
cat <<EOF > backend/bethpage/models.py
from typing import Generic, TypeVar
from django.db import models
T = TypeVar("T", bound="BaseModel")
class BaseQuerySet(models.QuerySet[T], Generic[T]): pass
EOF
cat <<EOF > backend/bethpage/settings.py
from pathlib import Path
BASE_DIR = Path(__file__).resolve().parent.parent
INSTALLED_APPS = []
EOF
cat <<EOF > backend/mypy.ini
[mypy]
python_version = 3.12
mypy_path = backend
plugins =
mypy_django_plugin.main
strict = True
[mypy.plugins.django-stubs]
django_settings_module = bethpage.settings
EOF
mypy backend --config-file backend/mypy.ini --show-traceback Out:
|
The core of the problem is in unresolved quoted name in typevar bound: replacing |
PRs to django-stubs are welcome :) |
Crash Report
Mypy was working fine on my django project until about a week ago, when I started getting this error. I'm not sure what caused it. My python code used to be in the root directory of my project and now I moved it to the
backend/
directory, and the problem started around then, but I'm not sure whether that is related.I am using pre-commit and have mypy set up in my .pre-commit-config.yaml. The error actually only happens when I run mypy as part of pre-commit. If I just run
mypy .
from the command line, it works fine.Presently, whenever I run pre-commit, I get an INTERNAL ERROR (details below).
Traceback
To Reproduce
This crash happens any time I change any file in my
backend/
directory and then rungit add -A; pre-commit
.It does not happen if I just run
cd backend; mypy .
If I use the
--no-incremental
flag or delete the cache directory, the problem still persists.If I open up
backend/bethpage/models.py
and add a line that just says "pass" somewhere above line 23 (the line cited in the error), then rungit add -A; pre-commit
, it actually works fine and completes without errors. The next time I need to commit something, I'll get the error again, but I can just remove that "pass" line and once again, the error goes away.Here is the beginning of that
/backend/bethpage/models.py
file:Your Environment
.pre-commit-config.yaml
mypy.ini
The text was updated successfully, but these errors were encountered: