diff --git a/django-stubs/db/models/fields/__init__.pyi b/django-stubs/db/models/fields/__init__.pyi index 985b4bf..98c91e2 100644 --- a/django-stubs/db/models/fields/__init__.pyi +++ b/django-stubs/db/models/fields/__init__.pyi @@ -90,9 +90,12 @@ class Field(RegisterLookupMixin, Generic[_ST, _GT]): # class access @overload def __get__(self: _T, instance: None, owner) -> _T: ... - # instance access + # Model instance access @overload - def __get__(self, instance, owner) -> _GT: ... + def __get__(self, instance: Model, owner) -> _GT: ... + # non-Model instances + @overload + def __get__(self: _T, instance, owner) -> _T: ... def deconstruct(self) -> Any: ... def set_attributes_from_name(self, name: str) -> None: ... def db_type(self, connection: Any) -> str: ... diff --git a/test-data/typecheck/fields/test_base.yml b/test-data/typecheck/fields/test_base.yml index d3782d1..16d98a8 100644 --- a/test-data/typecheck/fields/test_base.yml +++ b/test-data/typecheck/fields/test_base.yml @@ -123,4 +123,12 @@ content: | from django.db import models class MyUser(models.Model): - name = models.CharField(max_length=100) \ No newline at end of file + name = models.CharField(max_length=100) + +- case: fields_on_non_model_classes_resolve_to_field_type + main: | + from django.db import models + class MyClass: + myfield: models.IntegerField[int, int] + reveal_type(MyClass.myfield) # N: Revealed type is 'django.db.models.fields.IntegerField[builtins.int, builtins.int]' + reveal_type(MyClass().myfield) # N: Revealed type is 'django.db.models.fields.IntegerField[builtins.int, builtins.int]'