mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-06 20:24:31 +08:00
Fix type errors on other models' managers when using objects = models.Manager() in Model. (#34)
* Fix bug where models with a class variable using a manager defined would interfere with other managers. - Fill in the type argument for that particular instance of the manager, rather than modifying the bases of the Manager type. - Instantiate a new Instance from determine_proper_manager_type so The code doesn't crash under mypy-mypyc. * Use helpers.reparametrize_instance per review comment. * Updated ignored errors in Django test for get_objects_or_404. - For some reason, `Manager[nothing]` is now removed from expected types. However, I think this makes sense anyway, as Manager is a subclass of QuerySet.
This commit is contained in:
committed by
Maxim Kurnikov
parent
050c1b8887
commit
86c63d790b
@@ -64,13 +64,20 @@ def determine_proper_manager_type(ctx: FunctionContext) -> Type:
|
||||
if not isinstance(ret, Instance):
|
||||
return ret
|
||||
|
||||
has_manager_base = False
|
||||
for i, base in enumerate(ret.type.bases):
|
||||
if base.type.fullname() in {helpers.MANAGER_CLASS_FULLNAME,
|
||||
helpers.RELATED_MANAGER_CLASS_FULLNAME,
|
||||
helpers.BASE_MANAGER_CLASS_FULLNAME}:
|
||||
ret.type.bases[i] = Instance(base.type, [Instance(outer_model_info, [])])
|
||||
return ret
|
||||
return ret
|
||||
has_manager_base = True
|
||||
break
|
||||
|
||||
if has_manager_base:
|
||||
# Fill in the manager's type argument from the outer model
|
||||
new_type_args = [Instance(outer_model_info, [])]
|
||||
return helpers.reparametrize_instance(ret, new_type_args)
|
||||
else:
|
||||
return ret
|
||||
|
||||
|
||||
def return_user_model_hook(ctx: FunctionContext) -> Type:
|
||||
|
||||
Reference in New Issue
Block a user