From 233e0471174d8fb4bfad3ab36ece409310174edc Mon Sep 17 00:00:00 2001 From: Maxim Kurnikov Date: Sat, 10 Nov 2018 19:42:45 +0300 Subject: [PATCH] add more fields and more tests --- django-stubs/db/models/__init__.pyi | 5 ++++- django-stubs/db/models/fields/__init__.pyi | 11 +++++++++++ test/test-data/check-model-fields.test | 6 ++++++ test/test-data/check-postgres-fields.test | 19 ++++++++++++++++--- 4 files changed, 37 insertions(+), 4 deletions(-) diff --git a/django-stubs/db/models/__init__.pyi b/django-stubs/db/models/__init__.pyi index 796e6af..ccafd1f 100644 --- a/django-stubs/db/models/__init__.pyi +++ b/django-stubs/db/models/__init__.pyi @@ -2,5 +2,8 @@ from .base import Model as Model from .fields import (AutoField as AutoField, IntegerField as IntegerField, + SmallIntegerField as SmallIntegerField, CharField as CharField, - Field as Field) \ No newline at end of file + Field as Field, + SlugField as SlugField, + TextField as TextField) diff --git a/django-stubs/db/models/fields/__init__.pyi b/django-stubs/db/models/fields/__init__.pyi index d57bff7..f7a0dac 100644 --- a/django-stubs/db/models/fields/__init__.pyi +++ b/django-stubs/db/models/fields/__init__.pyi @@ -14,6 +14,10 @@ class IntegerField(Field): def __get__(self, instance, owner) -> int: ... +class SmallIntegerField(IntegerField): + pass + + class AutoField(Field): def __get__(self, instance, owner) -> int: ... @@ -24,3 +28,10 @@ class CharField(Field): **kwargs): ... def __get__(self, instance, owner) -> str: ... + +class SlugField(CharField): + pass + + +class TextField(Field): + def __get__(self, instance, owner) -> str: ... diff --git a/test/test-data/check-model-fields.test b/test/test-data/check-model-fields.test index d1cca41..164ad6e 100644 --- a/test/test-data/check-model-fields.test +++ b/test/test-data/check-model-fields.test @@ -4,9 +4,15 @@ from django.db import models class User(models.Model): id = models.AutoField(primary_key=True) + small_int = models.SmallIntegerField() name = models.CharField(max_length=255) + slug = models.SlugField(max_length=255) + text = models.TextField() user = User() 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.slug) # E: Revealed type is 'builtins.str' +reveal_type(user.text) # E: Revealed type is 'builtins.str' [out] diff --git a/test/test-data/check-postgres-fields.test b/test/test-data/check-postgres-fields.test index e469399..2de1691 100644 --- a/test/test-data/check-postgres-fields.test +++ b/test/test-data/check-postgres-fields.test @@ -1,6 +1,17 @@ -[case testArrayField] -import typing +[case testArrayFieldJsonField] +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.contrib.postgres.fields import ArrayField @@ -12,4 +23,6 @@ class User(models.Model): user = User() 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*]' -[out] \ No newline at end of file +[out] + +