From 7701957e4f5fac437b6b027a40e5aaeb26b87a5a Mon Sep 17 00:00:00 2001 From: rolandcrosby-check <88003730+rolandcrosby-check@users.noreply.github.com> Date: Sat, 8 Jan 2022 02:48:29 -0500 Subject: [PATCH] Fix annotation of ModelAdmin.get_object (#812) * Fix annotation of ModelAdmin.get_object The type annotation in django-stubs indicated that the type of the `from_field` argument to `ModelAdmin.get_object` should be `None`. In fact, `None` is the default value of that argument. If the argument is not `None`, [it is passed to a model's `_meta.get_field` method][impl], which takes an argument of type `Union[Callable[..., Any], str`. [impl]: https://github.com/django/django/blob/ac5cc6cf01463d90aa333d5f6f046c311019827b/django/contrib/admin/options.py#L767 * Fix formatting --- django-stubs/contrib/admin/options.pyi | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/django-stubs/contrib/admin/options.pyi b/django-stubs/contrib/admin/options.pyi index bff6d7f..ca3d74c 100644 --- a/django-stubs/contrib/admin/options.pyi +++ b/django-stubs/contrib/admin/options.pyi @@ -171,7 +171,9 @@ class ModelAdmin(BaseModelAdmin[_ModelT]): def get_form(self, request: Any, obj: Optional[_ModelT] = ..., change: bool = ..., **kwargs: Any): ... def get_changelist(self, request: HttpRequest, **kwargs: Any) -> Type[ChangeList]: ... def get_changelist_instance(self, request: HttpRequest) -> ChangeList: ... - def get_object(self, request: HttpRequest, object_id: str, from_field: None = ...) -> Optional[_ModelT]: ... + def get_object( + self, request: HttpRequest, object_id: str, from_field: Optional[Union[Callable[..., Any], str]] = ... + ) -> Optional[_ModelT]: ... def get_changelist_form(self, request: Any, **kwargs: Any): ... def get_changelist_formset(self, request: Any, **kwargs: Any): ... def get_formsets_with_inlines(self, request: HttpRequest, obj: Optional[_ModelT] = ...) -> Iterator[Any]: ...