Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve BaseManager, Manager types (#205)
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](https://github.com/django/django/blob/a576ef98aea2709741f32a863cff3c7a54172ded/django/db/models/manager.py#L42)) - `BaseManager.from_queryset()`: `queryset_class` is now generic, and the return type is made more specific ([see implementation](https://github.com/django/django/blob/a576ef98aea2709741f32a863cff3c7a54172ded/django/db/models/manager.py#L108)). This allows code like this to receive type information: ```python 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](https://github.com/django/django/blob/a576ef98aea2709741f32a863cff3c7a54172ded/django/db/models/manager.py#L83)). - `Manager._queryset_class`: This property is assigned dynamically by `BaseManager.from_queryset()` ([see implementation](https://github.com/django/django/blob/a576ef98aea2709741f32a863cff3c7a54172ded/django/db/models/manager.py#L115))
- Loading branch information