mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-15 08:17:08 +08:00
52/model subtypes dont typecheck (#55)
* Fix problem where Model instancess are not considered subtypes of each other due to fallback_to_any = True. Fixes #52. - Added a stub for __getstate__ to Model. - Added a stub for clean() to Model. - Correct arg type for sort_dependencies so they are covariant (Iterable rather than List). Test ignores: - Added some test ignores in cases where a model inherits from 2 different base models. - Added some test ignores for cases that MyPy flags as errors due to variable redefinitions or imports that are incompatible types. * Address review comment.
This commit is contained in:
committed by
Maxim Kurnikov
parent
9288c34648
commit
71fb0432f3
@@ -1,5 +1,4 @@
|
||||
from collections import OrderedDict
|
||||
from typing import Any, Callable, Dict, Iterator, List, Optional, Tuple, Type, Union
|
||||
from typing import Any, Callable, Dict, Iterator, List, Optional, Tuple, Type, Union, Iterable
|
||||
|
||||
from django.apps.config import AppConfig
|
||||
from django.db.models.base import Model
|
||||
@@ -33,5 +32,5 @@ def serialize(
|
||||
) -> Optional[Union[bytes, str]]: ...
|
||||
def deserialize(format: str, stream_or_string: Any, **options: Any) -> Union[Iterator[Any], Deserializer]: ...
|
||||
def sort_dependencies(
|
||||
app_list: Union[List[Tuple[AppConfig, None]], List[Tuple[str, List[Type[Model]]]]]
|
||||
app_list: Union[Iterable[Tuple[AppConfig, None]], Iterable[Tuple[str, Iterable[Type[Model]]]]]
|
||||
) -> List[Type[Model]]: ...
|
||||
|
||||
@@ -8,6 +8,7 @@ _Self = TypeVar("_Self", bound="Model")
|
||||
|
||||
class Model(metaclass=ModelBase):
|
||||
class DoesNotExist(Exception): ...
|
||||
class MultipleObjectsReturned(Exception): ...
|
||||
class Meta: ...
|
||||
_meta: Any
|
||||
_default_manager: Manager[Model]
|
||||
@@ -15,6 +16,7 @@ class Model(metaclass=ModelBase):
|
||||
def __init__(self: _Self, *args, **kwargs) -> None: ...
|
||||
def delete(self, using: Any = ..., keep_parents: bool = ...) -> Tuple[int, Dict[str, int]]: ...
|
||||
def full_clean(self, exclude: Optional[List[str]] = ..., validate_unique: bool = ...) -> None: ...
|
||||
def clean(self) -> None: ...
|
||||
def clean_fields(self, exclude: List[str] = ...) -> None: ...
|
||||
def validate_unique(self, exclude: List[str] = ...) -> None: ...
|
||||
def save(
|
||||
@@ -34,6 +36,7 @@ class Model(metaclass=ModelBase):
|
||||
): ...
|
||||
def refresh_from_db(self: _Self, using: Optional[str] = ..., fields: Optional[List[str]] = ...) -> _Self: ...
|
||||
def get_deferred_fields(self) -> Set[str]: ...
|
||||
def __getstate__(self) -> dict: ...
|
||||
|
||||
class ModelStateFieldsCacheDescriptor: ...
|
||||
|
||||
|
||||
Reference in New Issue
Block a user