Skip to content

Commit

Permalink
remove non-model overload for Field descriptor
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 Nov 9, 2023
1 parent e377bcf commit 82a2c16
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 26 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 @@ -187,10 +187,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
12 changes: 2 additions & 10 deletions django-stubs/db/models/fields/files.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ from django.db.models.fields import Field, _ErrorMessagesMapping, _FieldChoices
from django.db.models.query_utils import DeferredAttribute
from django.utils._os import _PathCompatible
from django.utils.functional import _StrOrPromise
from typing_extensions import Self

class FieldFile(File):
instance: Model
Expand Down Expand Up @@ -75,11 +74,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 generate_filename(self, instance: Model | None, filename: _PathCompatible) -> str: ...
def __get__(self, instance: object, owner: Any) -> Any: ...

class ImageFileDescriptor(FileDescriptor):
field: ImageField
Expand All @@ -103,8 +98,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 @@ -98,10 +98,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]]: ...
@property
def related_fields(self) -> list[tuple[Field, Field]]: ...
Expand Down Expand Up @@ -198,10 +195,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: ...

_To = TypeVar("_To", bound=Model)

Expand Down Expand Up @@ -256,10 +250,7 @@ class ManyToManyField(RelatedField[Any, Any], Generic[_To, _M]):
def __get__(self, instance: None, owner: Any) -> ManyToManyDescriptor[_M]: ...
# Model instance access
@overload
def __get__(self, instance: Model, owner: Any) -> ManyRelatedManager[_To]: ...
# non-Model instances
@overload
def __get__(self, instance: Any, owner: Any) -> Self: ...
def __get__(self, instance: object, owner: Any) -> ManyRelatedManager[_To]: ...
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 82a2c16

Please sign in to comment.