Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add explicit overload to Field subclasses #1900

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions django-stubs/contrib/auth/models.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ from django.contrib.contenttypes.models import ContentType
from django.db import models
from django.db.models import QuerySet
from django.db.models.base import Model
from django.db.models.expressions import Combinable
from django.db.models.manager import EmptyManager
from django.utils.functional import _StrOrPromise
from typing_extensions import Self, TypeAlias
Expand All @@ -23,9 +24,9 @@ class Permission(models.Model):
content_type_id: int
objects: ClassVar[PermissionManager]

name = models.CharField(max_length=255)
content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
codename = models.CharField(max_length=100)
Comment on lines -26 to -28
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having explicit assignments feels a bit weird in a stub file and was causing issues when testing without the plugin (had error code var-annotated)

name: models.CharField[str | int | Combinable, str]
content_type: models.ForeignKey[ContentType | Combinable, ContentType]
codename: models.CharField[str | int | Combinable, str]
def natural_key(self) -> tuple[str, str, str]: ...

class GroupManager(models.Manager[Group]):
Expand All @@ -34,7 +35,7 @@ class GroupManager(models.Manager[Group]):
class Group(models.Model):
objects: ClassVar[GroupManager]

name = models.CharField(max_length=150)
name: models.CharField[str | int | Combinable, str]
permissions = models.ManyToManyField(Permission)
Copy link
Contributor Author

@Viicos Viicos Feb 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... however I can't explicitly annotate permissions: models.ManyToManyField[..., ...] as the second type var is solved by the plugin to a class that doesn't exist in stubs nor at runtime

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

def natural_key(self) -> tuple[str]: ...

Expand Down
Loading
Loading