mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-08 21:14:49 +08:00
add more fields and more tests
This commit is contained in:
@@ -2,5 +2,8 @@ from .base import Model as Model
|
|||||||
|
|
||||||
from .fields import (AutoField as AutoField,
|
from .fields import (AutoField as AutoField,
|
||||||
IntegerField as IntegerField,
|
IntegerField as IntegerField,
|
||||||
|
SmallIntegerField as SmallIntegerField,
|
||||||
CharField as CharField,
|
CharField as CharField,
|
||||||
Field as Field)
|
Field as Field,
|
||||||
|
SlugField as SlugField,
|
||||||
|
TextField as TextField)
|
||||||
|
|||||||
@@ -14,6 +14,10 @@ class IntegerField(Field):
|
|||||||
def __get__(self, instance, owner) -> int: ...
|
def __get__(self, instance, owner) -> int: ...
|
||||||
|
|
||||||
|
|
||||||
|
class SmallIntegerField(IntegerField):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class AutoField(Field):
|
class AutoField(Field):
|
||||||
def __get__(self, instance, owner) -> int: ...
|
def __get__(self, instance, owner) -> int: ...
|
||||||
|
|
||||||
@@ -24,3 +28,10 @@ class CharField(Field):
|
|||||||
**kwargs): ...
|
**kwargs): ...
|
||||||
def __get__(self, instance, owner) -> str: ...
|
def __get__(self, instance, owner) -> str: ...
|
||||||
|
|
||||||
|
|
||||||
|
class SlugField(CharField):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class TextField(Field):
|
||||||
|
def __get__(self, instance, owner) -> str: ...
|
||||||
|
|||||||
@@ -4,9 +4,15 @@ from django.db import models
|
|||||||
|
|
||||||
class User(models.Model):
|
class User(models.Model):
|
||||||
id = models.AutoField(primary_key=True)
|
id = models.AutoField(primary_key=True)
|
||||||
|
small_int = models.SmallIntegerField()
|
||||||
name = models.CharField(max_length=255)
|
name = models.CharField(max_length=255)
|
||||||
|
slug = models.SlugField(max_length=255)
|
||||||
|
text = models.TextField()
|
||||||
|
|
||||||
user = User()
|
user = User()
|
||||||
reveal_type(user.id) # E: Revealed type is 'builtins.int'
|
reveal_type(user.id) # E: Revealed type is 'builtins.int'
|
||||||
|
reveal_type(user.small_int) # E: Revealed type is 'builtins.int'
|
||||||
reveal_type(user.name) # E: Revealed type is 'builtins.str'
|
reveal_type(user.name) # E: Revealed type is 'builtins.str'
|
||||||
|
reveal_type(user.slug) # E: Revealed type is 'builtins.str'
|
||||||
|
reveal_type(user.text) # E: Revealed type is 'builtins.str'
|
||||||
[out]
|
[out]
|
||||||
|
|||||||
@@ -1,6 +1,17 @@
|
|||||||
[case testArrayField]
|
[case testArrayFieldJsonField]
|
||||||
import typing
|
from django.db import models
|
||||||
|
from django.contrib.postgres.fields import ArrayField
|
||||||
|
|
||||||
|
|
||||||
|
class User(models.Model):
|
||||||
|
array = ArrayField(base_field=models.Field())
|
||||||
|
|
||||||
|
user = User()
|
||||||
|
reveal_type(user.array) # E: Revealed type is 'builtins.list[Any]'
|
||||||
|
[out]
|
||||||
|
|
||||||
|
|
||||||
|
[case testArrayFieldBaseFieldParsedIntoGenericAttribute]
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.contrib.postgres.fields import ArrayField
|
from django.contrib.postgres.fields import ArrayField
|
||||||
|
|
||||||
@@ -13,3 +24,5 @@ user = User()
|
|||||||
reveal_type(user.members) # E: Revealed type is 'builtins.list[builtins.int*]'
|
reveal_type(user.members) # E: Revealed type is 'builtins.list[builtins.int*]'
|
||||||
reveal_type(user.members_as_text) # E: Revealed type is 'builtins.list[builtins.str*]'
|
reveal_type(user.members_as_text) # E: Revealed type is 'builtins.list[builtins.str*]'
|
||||||
[out]
|
[out]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user