mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-06 20:24:31 +08:00
allow to use fields as Field objects outside Model classes
This commit is contained in:
@@ -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: ...
|
||||
|
||||
@@ -124,3 +124,11 @@
|
||||
from django.db import models
|
||||
class MyUser(models.Model):
|
||||
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]'
|
||||
|
||||
Reference in New Issue
Block a user