Skip to content

Commit

Permalink
Fix ContentType model fields to be infered as Any, refs #2446 (#2483
Browse files Browse the repository at this point in the history
)
  • Loading branch information
sobolevn authored Jan 15, 2025
1 parent 9fe8bb0 commit c1f0b2e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions django-stubs/contrib/contenttypes/models.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...
Expand Down
13 changes: 13 additions & 0 deletions tests/typecheck/contrib/contenttypes/test_models.yml
Original file line number Diff line number Diff line change
@@ -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",)

0 comments on commit c1f0b2e

Please sign in to comment.