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:
Seth Yastrov
2019-03-28 21:13:02 +01:00
committed by Maxim Kurnikov
parent 9288c34648
commit 71fb0432f3
7 changed files with 87 additions and 14 deletions
+3
View File
@@ -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: ...