Skip to content

type[Model] no longer allows access to .objects in django-stubs 4.2.4 #1684

Closed
@johnthagen

Description

@johnthagen

Bug report

What's wrong

Prior to django-stubs 4.2.4 / mypy 1.5.1, the you could type hint a variable/class attribute as type[Model] and access .objects on it:

from django.contrib.auth.models import User
from django.db.models import Model

user_type: type[Model] = User

users = user_type.objects.all()

Note that is the real usage, the variable is a class variable that is set by derived classes.

But as of the latest django-stubs and mypy, this generates a type check error:

error: "type[Model]" has no attribute "objects"  [attr-defined]

How is that should be

No type check errors.

System information

  • OS: macOS
  • python version: 3.10.11
  • django version: 4.2.5
  • mypy version: 1.5.1
  • django-stubs version: 4.2.4
  • django-stubs-ext version: 4.2.2

Mypy configuration:

[tool.mypy]
ignore_missing_imports = true
strict = true

disallow_subclassing_any = false
disallow_untyped_decorators = false
warn_return_any = false

plugins = [
    "pydantic.mypy",
    "mypy_django_plugin.main",
]

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions