Skip to content

Commit f311e79

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

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
@@ -184,10 +184,7 @@ class Field(RegisterLookupMixin, Generic[_ST, _GT]):
184184
def __get__(self, instance: None, owner: Any) -> _FieldDescriptor[Self]: ...
185185
# Model instance access
186186
@overload
187-
def __get__(self, instance: Model, owner: Any) -> _GT: ...
188-
# non-Model instances
189-
@overload
190-
def __get__(self, instance: Any, owner: Any) -> Self: ...
187+
def __get__(self, instance: object, owner: Any) -> _GT: ...
191188
def deconstruct(self) -> tuple[str, str, Sequence[Any], dict[str, Any]]: ...
192189
def set_attributes_from_name(self, name: str) -> None: ...
193190
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
@@ -13,7 +13,6 @@ from django.db.models.utils import AltersData
1313
from django.utils._os import _PathCompatible
1414
from django.utils.choices import _Choices
1515
from django.utils.functional import _StrOrPromise
16-
from typing_extensions import Self
1716

1817
class FieldFile(File, AltersData):
1918
instance: Model
@@ -85,10 +84,7 @@ class FileField(Field):
8584
def __get__(self, instance: None, owner: Any) -> FileDescriptor: ...
8685
# Model instance access
8786
@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: ...
87+
def __get__(self, instance: object, owner: Any) -> Any: ...
9288
def generate_filename(self, instance: Model | None, filename: _PathCompatible) -> str: ...
9389

9490
class ImageFileDescriptor(FileDescriptor):
@@ -113,8 +109,5 @@ class ImageField(FileField):
113109
def __get__(self, instance: None, owner: Any) -> ImageFileDescriptor: ...
114110
# Model instance access
115111
@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: ...
112+
def __get__(self, instance: object, owner: Any) -> Any: ...
120113
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]]: ...
@@ -231,10 +228,7 @@ class OneToOneField(ForeignKey[_ST, _GT]):
231228
def __get__(self, instance: None, owner: Any) -> ForwardOneToOneDescriptor[Self]: ...
232229
# Model instance access
233230
@overload
234-
def __get__(self, instance: Model, owner: Any) -> _GT: ...
235-
# non-Model instances
236-
@overload
237-
def __get__(self, instance: Any, owner: Any) -> Self: ...
231+
def __get__(self, instance: object, owner: Any) -> _GT: ...
238232

239233
_Through = TypeVar("_Through", bound=Model)
240234
_To = TypeVar("_To", bound=Model)
@@ -290,10 +284,7 @@ class ManyToManyField(RelatedField[Any, Any], Generic[_To, _Through]):
290284
def __get__(self, instance: None, owner: Any) -> ManyToManyDescriptor[_To, _Through]: ...
291285
# Model instance access
292286
@overload
293-
def __get__(self, instance: Model, owner: Any) -> ManyRelatedManager[_To, _Through]: ...
294-
# non-Model instances
295-
@overload
296-
def __get__(self, instance: Any, owner: Any) -> Self: ...
287+
def __get__(self, instance: object, owner: Any) -> ManyRelatedManager[_To, _Through]: ...
297288
def get_path_info(self, filtered_relation: FilteredRelation | None = ...) -> list[PathInfo]: ...
298289
def get_reverse_path_info(self, filtered_relation: FilteredRelation | None = ...) -> list[PathInfo]: ...
299290
def contribute_to_related_class(self, cls: type[Model], related: RelatedField) -> None: ...

0 commit comments

Comments
 (0)