We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Self
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
In e.g. django.db.models.Model.[a]refresh_from_db, Self is used in a contravariant position:
django.db.models.Model.[a]refresh_from_db
django-stubs/django-stubs/db/models/base.pyi
Lines 96 to 107 in 0be73eb
When I override this in my own model as e.g.
@override def refresh_from_db( self, using: str | None = None, fields: Iterable[str] | None = None, from_queryset: QuerySet[Self] | None = None, ) -> None:
it violates the LSP, as explained in https://discuss.python.org/t/unsoundness-of-contravariant-self-type/86338. On pyright>=1.1.399, it will reportIncompatibleMethodOverride.
pyright>=1.1.399
reportIncompatibleMethodOverride
The workaround is to instead use QuerySet[Any] in the code above.
QuerySet[Any]
Perhaps a self: T with QuerySet[T] could work here? I'm not sure whether that'd make it theoretically sound, but it might be worth a shot 🤷🏻.
self: T
QuerySet[T]
python
django
mypy
pyright==1.1.399
basedpyright==1.28.5
django-stubs
django-stubs-ext
The text was updated successfully, but these errors were encountered:
PR is welcome! Thanks for noticing!
Sorry, something went wrong.
No branches or pull requests
In e.g.
django.db.models.Model.[a]refresh_from_db
,Self
is used in a contravariant position:django-stubs/django-stubs/db/models/base.pyi
Lines 96 to 107 in 0be73eb
When I override this in my own model as e.g.
it violates the LSP, as explained in https://discuss.python.org/t/unsoundness-of-contravariant-self-type/86338. On
pyright>=1.1.399
, it willreportIncompatibleMethodOverride
.The workaround is to instead use
QuerySet[Any]
in the code above.Perhaps a
self: T
withQuerySet[T]
could work here? I'm not sure whether that'd make it theoretically sound, but it might be worth a shot 🤷🏻.System information
python
version: 3.13django
version: 5.2mypy
version:pyright==1.1.399
orbasedpyright==1.28.5
django-stubs
version: 5.1.3django-stubs-ext
version: 5.1.3The text was updated successfully, but these errors were encountered: