mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-10 05:51:53 +08:00
support for models.Model.objects, abstract mixins
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
[mypy]
|
||||
plugins =
|
||||
mypy_django_plugin.plugins.postgres_fields,
|
||||
mypy_django_plugin.plugins.related_fields
|
||||
mypy_django_plugin.plugin
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
[case testBasicModelFields]
|
||||
from django.db import models
|
||||
|
||||
|
||||
class User(models.Model):
|
||||
id = models.AutoField(primary_key=True)
|
||||
small_int = models.SmallIntegerField()
|
||||
@@ -15,4 +14,4 @@ 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]
|
||||
[out]
|
||||
@@ -55,4 +55,17 @@ class Profile(models.Model):
|
||||
|
||||
profile = Profile()
|
||||
reveal_type(profile.user_id) # E: Revealed type is 'builtins.int'
|
||||
[out]
|
||||
[out]
|
||||
|
||||
[case testToParameterKeywordMaybeAbsent]
|
||||
from django.db import models
|
||||
|
||||
class User(models.Model):
|
||||
pass
|
||||
|
||||
class Profile(models.Model):
|
||||
user = models.OneToOneField(User, on_delete=models.CASCADE, related_name='profile')
|
||||
|
||||
reveal_type(User().profile) # E: Revealed type is 'main.Profile'
|
||||
[out]
|
||||
|
||||
|
||||
24
test/test-data/check-objects-queryset.test
Normal file
24
test/test-data/check-objects-queryset.test
Normal file
@@ -0,0 +1,24 @@
|
||||
[case testEveryModelClassHasDefaultObjectsQuerySetAvailableAsAttribute]
|
||||
from django.db import models
|
||||
|
||||
class User(models.Model):
|
||||
pass
|
||||
|
||||
reveal_type(User.objects) # E: Revealed type is 'django.db.models.query.QuerySet[main.User]'
|
||||
[out]
|
||||
|
||||
[case testGetReturnsModelInstanceIfInheritedFromAbstractMixin]
|
||||
from django.db import models
|
||||
|
||||
class ModelMixin(models.Model):
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
class User(ModelMixin):
|
||||
pass
|
||||
|
||||
reveal_type(ModelMixin.objects)
|
||||
reveal_type(User.objects.get()) # E: Revealed type is 'main.User*'
|
||||
[out]
|
||||
main:10: error: Revealed type is 'Any'
|
||||
main:10: error: "Type[ModelMixin]" has no attribute "objects"
|
||||
@@ -14,9 +14,10 @@ MYPY_INI_PATH = ROOT_DIR / 'test' / 'plugins.ini'
|
||||
|
||||
class DjangoTestSuite(DataSuite):
|
||||
files = [
|
||||
'check-objects-queryset.test',
|
||||
'check-model-fields.test',
|
||||
'check-postgres-fields.test',
|
||||
'check-model-relations.test',
|
||||
'check-model-relations.test'
|
||||
]
|
||||
data_prefix = str(TEST_DATA_DIR)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user