Skip to content

Commit 5af709a

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

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
@@ -98,10 +98,7 @@ class ForeignObject(RelatedField[_ST, _GT]):
9898
def __get__(self, instance: None, owner: Any) -> ForwardManyToOneDescriptor[Self]: ...
9999
# Model instance access
100100
@overload
101-
def __get__(self, instance: Model, owner: Any) -> _GT: ...
102-
# non-Model instances
103-
@overload
104-
def __get__(self, instance: Any, owner: Any) -> Self: ...
101+
def __get__(self, instance: object, owner: Any) -> _GT: ...
105102
def resolve_related_fields(self) -> list[tuple[Field, Field]]: ...
106103
@property
107104
def related_fields(self) -> list[tuple[Field, Field]]: ...
@@ -198,10 +195,7 @@ class OneToOneField(ForeignKey[_ST, _GT]):
198195
def __get__(self, instance: None, owner: Any) -> ForwardOneToOneDescriptor[Self]: ...
199196
# Model instance access
200197
@overload
201-
def __get__(self, instance: Model, owner: Any) -> _GT: ...
202-
# non-Model instances
203-
@overload
204-
def __get__(self, instance: Any, owner: Any) -> Self: ...
198+
def __get__(self, instance: object, owner: Any) -> _GT: ...
205199

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

@@ -256,10 +250,7 @@ class ManyToManyField(RelatedField[Any, Any], Generic[_To, _M]):
256250
def __get__(self, instance: None, owner: Any) -> ManyToManyDescriptor[_M]: ...
257251
# Model instance access
258252
@overload
259-
def __get__(self, instance: Model, owner: Any) -> ManyRelatedManager[_To]: ...
260-
# non-Model instances
261-
@overload
262-
def __get__(self, instance: Any, owner: Any) -> Self: ...
253+
def __get__(self, instance: object, owner: Any) -> ManyRelatedManager[_To]: ...
263254
def get_path_info(self, filtered_relation: FilteredRelation | None = ...) -> list[PathInfo]: ...
264255
def get_reverse_path_info(self, filtered_relation: FilteredRelation | None = ...) -> list[PathInfo]: ...
265256
def contribute_to_related_class(self, cls: type[Model], related: RelatedField) -> None: ...

0 commit comments

Comments
 (0)