Skip to content

Commit 47d7e3c

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

File tree

3 files changed

+6
-25
lines changed

3 files changed

+6
-25
lines changed

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

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

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ from django.db.models.fields import Field, _ErrorMessagesMapping, _FieldChoices
1010
from django.db.models.query_utils import DeferredAttribute
1111
from django.utils._os import _PathCompatible
1212
from django.utils.functional import _StrOrPromise
13-
from typing_extensions import Self
1413

1514
class FieldFile(File):
1615
instance: Model
@@ -75,10 +74,7 @@ class FileField(Field):
7574
def __get__(self, instance: None, owner: Any) -> FileDescriptor: ...
7675
# Model instance access
7776
@overload
78-
def __get__(self, instance: Model, owner: Any) -> Any: ...
79-
# non-Model instances
80-
@overload
81-
def __get__(self, instance: Any, owner: Any) -> Self: ...
77+
def __get__(self, instance: object, owner: Any) -> Any: ...
8278
def generate_filename(self, instance: Model | None, filename: _PathCompatible) -> str: ...
8379

8480
class ImageFileDescriptor(FileDescriptor):
@@ -103,8 +99,5 @@ class ImageField(FileField):
10399
def __get__(self, instance: None, owner: Any) -> ImageFileDescriptor: ...
104100
# Model instance access
105101
@overload
106-
def __get__(self, instance: Model, owner: Any) -> Any: ...
107-
# non-Model instances
108-
@overload
109-
def __get__(self, instance: Any, owner: Any) -> Self: ...
102+
def __get__(self, instance: object, owner: Any) -> Any: ...
110103
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
@@ -126,10 +126,7 @@ class ForeignObject(RelatedField[_ST, _GT]):
126126
def __get__(self, instance: None, owner: Any) -> ForwardManyToOneDescriptor[Self]: ...
127127
# Model instance access
128128
@overload
129-
def __get__(self, instance: Model, owner: Any) -> _GT: ...
130-
# non-Model instances
131-
@overload
132-
def __get__(self, instance: Any, owner: Any) -> Self: ...
129+
def __get__(self, instance: object, owner: Any) -> _GT: ...
133130
def resolve_related_fields(self) -> list[tuple[Field, Field]]: ...
134131
@cached_property
135132
def related_fields(self) -> list[tuple[Field, Field]]: ...
@@ -226,10 +223,7 @@ class OneToOneField(ForeignKey[_ST, _GT]):
226223
def __get__(self, instance: None, owner: Any) -> ForwardOneToOneDescriptor[Self]: ...
227224
# Model instance access
228225
@overload
229-
def __get__(self, instance: Model, owner: Any) -> _GT: ...
230-
# non-Model instances
231-
@overload
232-
def __get__(self, instance: Any, owner: Any) -> Self: ...
226+
def __get__(self, instance: object, owner: Any) -> _GT: ...
233227

234228
_Through = TypeVar("_Through", bound=Model)
235229
_To = TypeVar("_To", bound=Model)
@@ -285,10 +279,7 @@ class ManyToManyField(RelatedField[Any, Any], Generic[_To, _Through]):
285279
def __get__(self, instance: None, owner: Any) -> ManyToManyDescriptor[_To, _Through]: ...
286280
# Model instance access
287281
@overload
288-
def __get__(self, instance: Model, owner: Any) -> ManyRelatedManager[_To]: ...
289-
# non-Model instances
290-
@overload
291-
def __get__(self, instance: Any, owner: Any) -> Self: ...
282+
def __get__(self, instance: object, owner: Any) -> ManyRelatedManager[_To]: ...
292283
def get_path_info(self, filtered_relation: FilteredRelation | None = ...) -> list[PathInfo]: ...
293284
def get_reverse_path_info(self, filtered_relation: FilteredRelation | None = ...) -> list[PathInfo]: ...
294285
def contribute_to_related_class(self, cls: type[Model], related: RelatedField) -> None: ...

0 commit comments

Comments
 (0)