Skip to content

Commit a4d581a

Browse files
fix handling of explicit objects annotation (typeddjango#2241) (#17)
Co-authored-by: Anthony Sottile <[email protected]>
1 parent ac84848 commit a4d581a

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

mypy_django_plugin/transformers/querysets.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,14 @@ def determine_proper_manager_type(ctx: FunctionContext) -> MypyType:
3333
assert isinstance(default_return_type, Instance)
3434

3535
outer_model_info = helpers.get_typechecker_api(ctx).scope.active_class()
36-
if outer_model_info is None or not outer_model_info.has_base(fullnames.MODEL_CLASS_FULLNAME):
36+
if (
37+
outer_model_info is None
38+
or not outer_model_info.has_base(fullnames.MODEL_CLASS_FULLNAME)
39+
or outer_model_info.self_type is None
40+
):
3741
return default_return_type
3842

39-
return helpers.reparametrize_instance(default_return_type, [Instance(outer_model_info, [])])
43+
return helpers.reparametrize_instance(default_return_type, [outer_model_info.self_type])
4044

4145

4246
def get_field_type_from_lookup(

tests/typecheck/managers/test_managers.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,7 @@
581581
- path: myapp/models.py
582582
content: |
583583
from typing import ClassVar, TypeVar
584+
from typing_extensions import Self
584585
from django.db import models
585586
586587
T = TypeVar("T", bound="MyModel")
@@ -595,7 +596,7 @@
595596
pass
596597
597598
class MySubModel(MyModel):
598-
objects: ClassVar[MySubManager["MySubModel"]] = MySubManager()
599+
objects: ClassVar[MySubManager[Self]] = MySubManager()
599600
600601
- case: subclass_manager_without_type_parameters_disallow_any_generics
601602
main: |

0 commit comments

Comments
 (0)