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]: ac5cc6cf01/django/contrib/admin/options.py (L767)

* Fix formatting
This commit is contained in:
rolandcrosby-check
2022-01-08 02:48:29 -05:00
committed by GitHub
parent fafb200e90
commit 7701957e4f

View File

@@ -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]: ...