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

Improve BaseManager, Manager types #205

Merged
merged 5 commits into from
Oct 21, 2023
Merged

Conversation

noelleleigh
Copy link

This PR makes a series of improvements to methods and properties of BaseManager and Manager:

  • BaseManager.deconstruct(): Most of the values in the return tuple can be null (see implementation)

  • BaseManager.from_queryset(): queryset_class is now generic, and the return type is made more specific (see implementation). This allows code like this to receive type information:

    class CustomQuerySet(models.QuerySet["User"]):
        ...
    
    class CustomManager(models.Manager.from_queryset(CustomQuerySet)):
        def get_queryset(self):
            qs = super().get_queryset() # ← Type checker knows get_queryset exists in the parent
            user = qs.get() # ← Inferred type is "User"
            return qs
  • BaseManager._get_queryset_methods(): Return dictionary values are functions (see implementation).

  • Manager._queryset_class: This property is assigned dynamically by BaseManager.from_queryset() (see implementation)

Copy link
Owner

@sbdchd sbdchd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thank you!!

@kodiakhq kodiakhq bot merged commit 6f1f9a3 into sbdchd:main Oct 21, 2023
2 checks passed
@noelleleigh noelleleigh deleted the improve-manager branch October 22, 2023 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants