diff --git a/django-stubs/contrib/contenttypes/models.pyi b/django-stubs/contrib/contenttypes/models.pyi index e7206aed0..1c15422e1 100644 --- a/django-stubs/contrib/contenttypes/models.pyi +++ b/django-stubs/contrib/contenttypes/models.pyi @@ -13,8 +13,8 @@ class ContentTypeManager(models.Manager[ContentType]): class ContentType(models.Model): id: int - app_label: models.CharField - model: models.CharField + app_label = models.CharField(max_length=100) + model = models.CharField(max_length=100) objects: ClassVar[ContentTypeManager] @property def name(self) -> str: ... diff --git a/tests/typecheck/contrib/contenttypes/test_models.yml b/tests/typecheck/contrib/contenttypes/test_models.yml new file mode 100644 index 000000000..284de2b1a --- /dev/null +++ b/tests/typecheck/contrib/contenttypes/test_models.yml @@ -0,0 +1,13 @@ +- case: test_contenttypes_models + main: | + from django.contrib.contenttypes.models import ContentType + + c = ContentType.objects.create(app_label='abc', model='abc') + reveal_type(c.id) # N: Revealed type is "builtins.int" + reveal_type(c.app_label) # N: Revealed type is "builtins.str" + reveal_type(c.model) # N: Revealed type is "builtins.str" + + ContentType.objects.create(app_label=[]) # E: Incompatible type for "app_label" of "ContentType" (got "List[Any]", expected "Union[str, int, Combinable]") [misc] + + custom_settings: | + INSTALLED_APPS = ("django.contrib.contenttypes",)