Skip to content

Commit

Permalink
fix handling of explicit objects annotation (typeddjango#2241)
Browse files Browse the repository at this point in the history
  • Loading branch information
asottile authored and asottile-sentry committed Jun 28, 2024
1 parent 5f0428b commit c725fde
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
8 changes: 6 additions & 2 deletions mypy_django_plugin/transformers/querysets.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,14 @@ def determine_proper_manager_type(ctx: FunctionContext) -> MypyType:
assert isinstance(default_return_type, Instance)

outer_model_info = helpers.get_typechecker_api(ctx).scope.active_class()
if outer_model_info is None or not outer_model_info.has_base(fullnames.MODEL_CLASS_FULLNAME):
if (
outer_model_info is None
or not outer_model_info.has_base(fullnames.MODEL_CLASS_FULLNAME)
or outer_model_info.self_type is None
):
return default_return_type

return helpers.reparametrize_instance(default_return_type, [Instance(outer_model_info, [])])
return helpers.reparametrize_instance(default_return_type, [outer_model_info.self_type])


def get_field_type_from_lookup(
Expand Down
3 changes: 2 additions & 1 deletion tests/typecheck/managers/test_managers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,7 @@
- path: myapp/models.py
content: |
from typing import ClassVar, TypeVar
from typing_extensions import Self
from django.db import models
T = TypeVar("T", bound="MyModel")
Expand All @@ -595,7 +596,7 @@
pass
class MySubModel(MyModel):
objects: ClassVar[MySubManager["MySubModel"]] = MySubManager()
objects: ClassVar[MySubManager[Self]] = MySubManager()
- case: subclass_manager_without_type_parameters_disallow_any_generics
main: |
Expand Down

0 comments on commit c725fde

Please sign in to comment.