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
When I share between multiple models a custom QuerySet with methods using Iterable[T] as arguments, the revealed typing is always the one of the first evaluated model.
I tried some alternatives like defining a specific queryset for each models, defining a specific manager for each models, using Manager.from_queryset, using QuerySet.as_manager, I always ends up with the same result. If someone could point me a workaround that would be great.
My specific use case involve overriding the bulk_create and bulk_update methods of the QuerySet to add some logging to it.
classBaseQuerySet(models.QuerySet[T], Generic[T]):
defexample_process_list(self, m: Collection[T]) ->None: ...
defexample_process_one(self, m: T) ->None: ...
classMyModel(models.Model):
objects=BaseQuerySet.as_manager()
classMyModel2(models.Model):
objects=BaseQuerySet.as_manager()
reveal_type(MyModel.objects.example_process_one) # Revealed type is "def (m: dj_stubs_demo.models.MyModel)"reveal_type(MyModel2.objects.example_process_one) # Revealed type is "def (m: dj_stubs_demo.models.MyModel2)"reveal_type(MyModel.objects.example_process_list) # Revealed type is "def (m: typing.Iterable[dj_stubs_demo.models.MyModel])"reveal_type(MyModel2.objects.example_process_list) # Revealed type is "def (m: typing.Iterable[dj_stubs_demo.models.MyModel])"
How is that should be
reveal_type(MyModel.objects.example_process_one) # Revealed type is "def (m: dj_stubs_demo.models.MyModel)"reveal_type(MyModel2.objects.example_process_one) # Revealed type is "def (m: dj_stubs_demo.models.MyModel2)"reveal_type(MyModel.objects.example_process_list) # Revealed type is "def (m: typing.Iterable[dj_stubs_demo.models.MyModel])"reveal_type(MyModel2.objects.example_process_list) # this one ---> Revealed type is "def (m: typing.Iterable[dj_stubs_demo.models.MyModel2])"
System information
OS: osx
python version: 3.11.3
django version: Django==4.2.9
mypy version: mypy==1.7.1
django-stubs version: django-stubs==4.2.7
django-stubs-ext version: django-stubs-ext==4.2.7
The text was updated successfully, but these errors were encountered:
Bug report
What's wrong
When I share between multiple models a custom QuerySet with methods using
Iterable[T]
as arguments, the revealed typing is always the one of the first evaluated model.I tried some alternatives like defining a specific queryset for each models, defining a specific manager for each models, using Manager.from_queryset, using QuerySet.as_manager, I always ends up with the same result. If someone could point me a workaround that would be great.
My specific use case involve overriding the bulk_create and bulk_update methods of the QuerySet to add some logging to it.
How is that should be
System information
python
version: 3.11.3django
version: Django==4.2.9mypy
version: mypy==1.7.1django-stubs
version: django-stubs==4.2.7django-stubs-ext
version: django-stubs-ext==4.2.7The text was updated successfully, but these errors were encountered: