You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
won't have an objects field in the type annotations:
"type[Self]" has no attribute "objects" [attr-defined]
This is kind of a duplicate, but the other bug was specific to AbstractUser.
How is that should be
It kind of makes sense, since it is an abstract model -- but sometimes you are writing an abstract model that needs to reference self.objects as you write abstract functions for the future inheritors.
This does not seem to work as a workaround:
class Meta:
abstract = False if typing.TYPE_CHECKING else True
This also does not seem to work:
if not typing.TYPE_CHECKING:
class Meta:
abstract = True
This IS a viable workaround it seems:
class MyModel(Model):
class Meta:
abstract = True
if typing.TYPE_CHECKING:
objects: Manager
Since there is a workaround, no fix is necessarily needed, but wanted to document this here.
I'd argue, though, that an abstract model ought to have objects: Manager type annotated?
System information
OS:
python version: 3.12
django version: 3.2.25
mypy version: 1.15.0
django-stubs version: 5.1.3
django-stubs-ext version: 5.1.3
The text was updated successfully, but these errors were encountered:
Bug report
A Model with
won't have an objects field in the type annotations:
"type[Self]" has no attribute "objects" [attr-defined]
This is kind of a duplicate, but the other bug was specific to AbstractUser.
How is that should be
It kind of makes sense, since it is an abstract model -- but sometimes you are writing an abstract model that needs to reference self.objects as you write abstract functions for the future inheritors.
This does not seem to work as a workaround:
This also does not seem to work:
This IS a viable workaround it seems:
Since there is a workaround, no fix is necessarily needed, but wanted to document this here.
I'd argue, though, that an abstract model ought to have objects: Manager type annotated?
System information
python
version: 3.12django
version: 3.2.25mypy
version: 1.15.0django-stubs
version: 5.1.3django-stubs-ext
version: 5.1.3The text was updated successfully, but these errors were encountered: