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

As_manager: Self not taken into account #1788

Closed
moranabadie opened this issue Oct 21, 2023 · 1 comment · Fixed by #1789
Closed

As_manager: Self not taken into account #1788

moranabadie opened this issue Oct 21, 2023 · 1 comment · Fixed by #1789
Labels
bug Something isn't working

Comments

@moranabadie
Copy link
Contributor

moranabadie commented Oct 21, 2023

Bug report

from django.db import models
from typing_extensions import Self
class MyQuerySet(BaseQuerySet):
       def example_simple(self) -> Self: ...

class MyModel(models.Model):
     objects = MyQuerySet.as_manager()
reveal_type(MyModel.objects.example_simple())  # -> Revealed type is "<nothing>" 

What's wrong

The issue lies in the type revelation within the custom QuerySet method that is supposed to return Self. Currently, it reveals the type as <nothing>, which indicates that the Self type isn't properly recognized or handled.

How is that should be

The correct and expected behavior should reveal the type accurately, as per the following expectation:

reveal_type(MyModel.objects.example_simple())  # -> Revealed type is "myapp.models.ManagerFromMyQuerySet[myapp.models.MyModel]"

System information

  • OS:
  • python 3.12
  • django 3.2.12
  • mypy 1.6.1
  • django-stubs 4.2.5
  • django-stubs-ext 4.2.5
@moranabadie moranabadie added the bug Something isn't working label Oct 21, 2023
moranabadie added a commit to moranabadie/django-stubs that referenced this issue Oct 21, 2023
moranabadie added a commit to moranabadie/django-stubs that referenced this issue Oct 21, 2023
@sobolevn
Copy link
Member

PR is welcome.

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

Successfully merging a pull request may close this issue.

2 participants