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 Jul 29, 2024
1 parent 4ca4721 commit 77557dd
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 24 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 @@ -185,10 +185,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
10 changes: 2 additions & 8 deletions django-stubs/db/models/fields/files.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,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 +110,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 @@ -233,10 +230,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 @@ -292,10 +286,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 77557dd

Please sign in to comment.