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

Generic Queryset INTERNALERROR #2479

Open
pelme opened this issue Jan 12, 2025 · 0 comments
Open

Generic Queryset INTERNALERROR #2479

pelme opened this issue Jan 12, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@pelme
Copy link
Contributor

pelme commented Jan 12, 2025

Bug report

Starting from django-stubs 5.0.3, the following example crashes with an internal mypy error:

from django.db import models
import typing as t

TMyBase = t.TypeVar("TMyBase", bound="MyBase")

class MyBase(models.Model):
	class Meta:
		abstract = True


class MyQuerySet(models.QuerySet[TMyBase]):
	pass

Output:

❯ pip freeze
asgiref==3.8.1
Django==5.0.4
django-stubs==5.0.3
django-stubs-ext==5.1.1
mypy==1.11.2
mypy-extensions==1.0.0
sqlparse==0.5.3
types-PyYAML==6.0.12.20241230
typing_extensions==4.12.2

❯ mypy --no-incremental --show-traceback .
./tstapp/models.py:11: error: INTERNAL ERROR -- Please try using mypy master on GitHub:
https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build
Please report a bug at https://github.com/python/mypy/issues
version: 1.11.2
Traceback (most recent call last):
  File "mypy/semanal.py", line 7087, in accept
  File "mypy/nodes.py", line 819, in accept
  File "mypy/semanal.py", line 874, in visit_func_def
  File "mypy/semanal.py", line 919, in analyze_func_def
  File "mypy/semanal.py", line 6742, in defer
AssertionError: Must not defer during final iteration
./tstapp/models.py:11: : note: use --pdb to drop into pdb

How is that should be

Running the same example with django-stubs 5.0.2:

❯ pip freeze
asgiref==3.8.1
Django==5.0.4
django-stubs==5.0.2
django-stubs-ext==5.1.1
mypy==1.10.1
mypy-extensions==1.0.0
sqlparse==0.5.3
types-PyYAML==6.0.12.20241230
typing_extensions==4.12.2

❯ mypy --show-traceback .
Success: no issues found in 13 source files

Example project

You can reproduce this by downloading this project (contains the model definition above) and running it locally:
tst.zip

Install django-stubs 5.0.2 without the problem:

pip install 'django-stubs[compatible-mypy]==5.0.2'

Install django-stubs 5.0.3 with the problem

pip install 'django-stubs[compatible-mypy]==5.0.2'

Workaround

The crash can be worked around by putting TMyBase after the MyBase definition.

System information

  • OS:
  • python version: 3.12.7
  • django version: I tested with 5.0.4 and 5.1.4 with the same result
@pelme pelme added the bug Something isn't working label Jan 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

1 participant