Skip to content

Commit

Permalink
remove non-model overload for Field descriptor (#4)
Browse files Browse the repository at this point in the history
(not upstreamed)

hopefully eventually can remove when python/mypy#5570 is solved
  • Loading branch information
asottile-sentry committed Apr 30, 2024
1 parent c6ea928 commit f311e79
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 25 deletions.
5 changes: 1 addition & 4 deletions django-stubs/db/models/fields/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,7 @@ class Field(RegisterLookupMixin, Generic[_ST, _GT]):
def __get__(self, instance: None, owner: Any) -> _FieldDescriptor[Self]: ...
# Model instance access
@overload
def __get__(self, instance: Model, owner: Any) -> _GT: ...
# non-Model instances
@overload
def __get__(self, instance: Any, owner: Any) -> Self: ...
def __get__(self, instance: object, owner: Any) -> _GT: ...
def deconstruct(self) -> tuple[str, str, Sequence[Any], dict[str, Any]]: ...
def set_attributes_from_name(self, name: str) -> None: ...
def db_type_parameters(self, connection: BaseDatabaseWrapper) -> DictWrapper: ...
Expand Down
11 changes: 2 additions & 9 deletions django-stubs/db/models/fields/files.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ from django.db.models.utils import AltersData
from django.utils._os import _PathCompatible
from django.utils.choices import _Choices
from django.utils.functional import _StrOrPromise
from typing_extensions import Self

class FieldFile(File, AltersData):
instance: Model
Expand Down Expand Up @@ -85,10 +84,7 @@ class FileField(Field):
def __get__(self, instance: None, owner: Any) -> FileDescriptor: ...
# Model instance access
@overload
def __get__(self, instance: Model, owner: Any) -> Any: ...
# non-Model instances
@overload
def __get__(self, instance: Any, owner: Any) -> Self: ...
def __get__(self, instance: object, owner: Any) -> Any: ...
def generate_filename(self, instance: Model | None, filename: _PathCompatible) -> str: ...

class ImageFileDescriptor(FileDescriptor):
Expand All @@ -113,8 +109,5 @@ class ImageField(FileField):
def __get__(self, instance: None, owner: Any) -> ImageFileDescriptor: ...
# Model instance access
@overload
def __get__(self, instance: Model, owner: Any) -> Any: ...
# non-Model instances
@overload
def __get__(self, instance: Any, owner: Any) -> Self: ...
def __get__(self, instance: object, owner: Any) -> Any: ...
def update_dimension_fields(self, instance: Model, force: bool = ..., *args: Any, **kwargs: Any) -> None: ...
15 changes: 3 additions & 12 deletions django-stubs/db/models/fields/related.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,7 @@ class ForeignObject(RelatedField[_ST, _GT]):
def __get__(self, instance: None, owner: Any) -> ForwardManyToOneDescriptor[Self]: ...
# Model instance access
@overload
def __get__(self, instance: Model, owner: Any) -> _GT: ...
# non-Model instances
@overload
def __get__(self, instance: Any, owner: Any) -> Self: ...
def __get__(self, instance: object, owner: Any) -> _GT: ...
def resolve_related_fields(self) -> list[tuple[Field, Field]]: ...
@cached_property
def related_fields(self) -> list[tuple[Field, Field]]: ...
Expand Down Expand Up @@ -231,10 +228,7 @@ class OneToOneField(ForeignKey[_ST, _GT]):
def __get__(self, instance: None, owner: Any) -> ForwardOneToOneDescriptor[Self]: ...
# Model instance access
@overload
def __get__(self, instance: Model, owner: Any) -> _GT: ...
# non-Model instances
@overload
def __get__(self, instance: Any, owner: Any) -> Self: ...
def __get__(self, instance: object, owner: Any) -> _GT: ...

_Through = TypeVar("_Through", bound=Model)
_To = TypeVar("_To", bound=Model)
Expand Down Expand Up @@ -290,10 +284,7 @@ class ManyToManyField(RelatedField[Any, Any], Generic[_To, _Through]):
def __get__(self, instance: None, owner: Any) -> ManyToManyDescriptor[_To, _Through]: ...
# Model instance access
@overload
def __get__(self, instance: Model, owner: Any) -> ManyRelatedManager[_To, _Through]: ...
# non-Model instances
@overload
def __get__(self, instance: Any, owner: Any) -> Self: ...
def __get__(self, instance: object, owner: Any) -> ManyRelatedManager[_To, _Through]: ...
def get_path_info(self, filtered_relation: FilteredRelation | None = ...) -> list[PathInfo]: ...
def get_reverse_path_info(self, filtered_relation: FilteredRelation | None = ...) -> list[PathInfo]: ...
def contribute_to_related_class(self, cls: type[Model], related: RelatedField) -> None: ...
Expand Down

0 comments on commit f311e79

Please sign in to comment.