Skip to content

Commit 209280c

Browse files
remove non-model overload for Field descriptor (#4)
(not upstreamed) hopefully eventually can remove when python/mypy#5570 is solved
1 parent 2777a3c commit 209280c

File tree

3 files changed

+6
-24
lines changed

3 files changed

+6
-24
lines changed

django-stubs/db/models/fields/__init__.pyi

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,7 @@ class Field(RegisterLookupMixin, Generic[_ST, _GT]):
185185
def __get__(self, instance: None, owner: Any) -> _FieldDescriptor[Self]: ...
186186
# Model instance access
187187
@overload
188-
def __get__(self, instance: Model, owner: Any) -> _GT: ...
189-
# non-Model instances
190-
@overload
191-
def __get__(self, instance: Any, owner: Any) -> Self: ...
188+
def __get__(self, instance: object, owner: Any) -> _GT: ...
192189
def deconstruct(self) -> tuple[str, str, Sequence[Any], dict[str, Any]]: ...
193190
def set_attributes_from_name(self, name: str) -> None: ...
194191
def db_type_parameters(self, connection: BaseDatabaseWrapper) -> DictWrapper: ...

django-stubs/db/models/fields/files.pyi

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,7 @@ class FileField(Field):
8585
def __get__(self, instance: None, owner: Any) -> FileDescriptor: ...
8686
# Model instance access
8787
@overload
88-
def __get__(self, instance: Model, owner: Any) -> Any: ...
89-
# non-Model instances
90-
@overload
91-
def __get__(self, instance: Any, owner: Any) -> Self: ...
88+
def __get__(self, instance: object, owner: Any) -> Any: ...
9289
def generate_filename(self, instance: Model | None, filename: _PathCompatible) -> str: ...
9390

9491
class ImageFileDescriptor(FileDescriptor):
@@ -113,8 +110,5 @@ class ImageField(FileField):
113110
def __get__(self, instance: None, owner: Any) -> ImageFileDescriptor: ...
114111
# Model instance access
115112
@overload
116-
def __get__(self, instance: Model, owner: Any) -> Any: ...
117-
# non-Model instances
118-
@overload
119-
def __get__(self, instance: Any, owner: Any) -> Self: ...
113+
def __get__(self, instance: object, owner: Any) -> Any: ...
120114
def update_dimension_fields(self, instance: Model, force: bool = ..., *args: Any, **kwargs: Any) -> None: ...

django-stubs/db/models/fields/related.pyi

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,7 @@ class ForeignObject(RelatedField[_ST, _GT]):
129129
def __get__(self, instance: None, owner: Any) -> ForwardManyToOneDescriptor[Self]: ...
130130
# Model instance access
131131
@overload
132-
def __get__(self, instance: Model, owner: Any) -> _GT: ...
133-
# non-Model instances
134-
@overload
135-
def __get__(self, instance: Any, owner: Any) -> Self: ...
132+
def __get__(self, instance: object, owner: Any) -> _GT: ...
136133
def resolve_related_fields(self) -> list[tuple[Field, Field]]: ...
137134
@cached_property
138135
def related_fields(self) -> list[tuple[Field, Field]]: ...
@@ -233,10 +230,7 @@ class OneToOneField(ForeignKey[_ST, _GT]):
233230
def __get__(self, instance: None, owner: Any) -> ForwardOneToOneDescriptor[Self]: ...
234231
# Model instance access
235232
@overload
236-
def __get__(self, instance: Model, owner: Any) -> _GT: ...
237-
# non-Model instances
238-
@overload
239-
def __get__(self, instance: Any, owner: Any) -> Self: ...
233+
def __get__(self, instance: object, owner: Any) -> _GT: ...
240234

241235
_Through = TypeVar("_Through", bound=Model)
242236
_To = TypeVar("_To", bound=Model)
@@ -292,10 +286,7 @@ class ManyToManyField(RelatedField[Any, Any], Generic[_To, _Through]):
292286
def __get__(self, instance: None, owner: Any) -> ManyToManyDescriptor[_To, _Through]: ...
293287
# Model instance access
294288
@overload
295-
def __get__(self, instance: Model, owner: Any) -> ManyRelatedManager[_To, _Through]: ...
296-
# non-Model instances
297-
@overload
298-
def __get__(self, instance: Any, owner: Any) -> Self: ...
289+
def __get__(self, instance: object, owner: Any) -> ManyRelatedManager[_To, _Through]: ...
299290
def get_path_info(self, filtered_relation: FilteredRelation | None = ...) -> list[PathInfo]: ...
300291
def get_reverse_path_info(self, filtered_relation: FilteredRelation | None = ...) -> list[PathInfo]: ...
301292
def contribute_to_related_class(self, cls: type[Model], related: RelatedField) -> None: ...

0 commit comments

Comments
 (0)