Skip to content

Commit

Permalink
fix subtypes of ModelWithMeta
Browse files Browse the repository at this point in the history
  • Loading branch information
jorenham committed Mar 12, 2024
1 parent 68cd002 commit 4232c7e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 37 deletions.
7 changes: 3 additions & 4 deletions django-stubs/contrib/auth/base_user.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ from django.db.models.base import Model
from django.db.models.expressions import Combinable
from django.db.models.fields import BooleanField

from django_stubs_ext.db.models import ModelWithMeta as _ModelWithMeta
from django_stubs_ext.db.models import ModelMeta as _ModelMeta

_T = TypeVar("_T", bound=Model)

Expand All @@ -15,15 +15,14 @@ class BaseUserManager(models.Manager[_T]):
def make_random_password(self, length: int = ..., allowed_chars: str = ...) -> str: ...
def get_by_natural_key(self, username: str | None) -> _T: ...

class AbstractBaseUser(_ModelWithMeta, models.Model):
class AbstractBaseUser(models.Model):
REQUIRED_FIELDS: ClassVar[list[str]]

password = models.CharField(max_length=128)
last_login = models.DateTimeField(blank=True, null=True)
is_active: bool | BooleanField[bool | Combinable, bool]

class Meta:
abstract: Literal[True]
Meta: ClassVar[type[_ModelMeta]]

def get_username(self) -> str: ...
def natural_key(self) -> tuple[str]: ...
Expand Down
12 changes: 5 additions & 7 deletions django-stubs/contrib/auth/models.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ from django.db.models.manager import EmptyManager
from django.utils.functional import _StrOrPromise
from typing_extensions import Self, TypeAlias

from django_stubs_ext.db.models import ModelWithMeta as _ModelWithMeta
from django_stubs_ext.db.models import ModelMeta as _ModelMeta

_AnyUser: TypeAlias = Model | AnonymousUser

Expand Down Expand Up @@ -58,13 +58,12 @@ class UserManager(BaseUserManager[_T]):
obj: Model | None = ...,
) -> QuerySet[_T]: ...

class PermissionsMixin(_ModelWithMeta, models.Model):
class PermissionsMixin(models.Model):
is_superuser = models.BooleanField()
groups = models.ManyToManyField(Group)
user_permissions = models.ManyToManyField(Permission)

class Meta:
abstract: Literal[True]
Meta: ClassVar[type[_ModelMeta]]

def get_user_permissions(self, obj: _AnyUser | None = ...) -> set[str]: ...
def get_group_permissions(self, obj: _AnyUser | None = ...) -> set[str]: ...
Expand All @@ -73,7 +72,7 @@ class PermissionsMixin(_ModelWithMeta, models.Model):
def has_perms(self, perm_list: Iterable[str], obj: _AnyUser | None = ...) -> bool: ...
def has_module_perms(self, app_label: str) -> bool: ...

class AbstractUser(_ModelWithMeta, AbstractBaseUser, PermissionsMixin):
class AbstractUser(AbstractBaseUser, PermissionsMixin):
username_validator: UnicodeUsernameValidator

username = models.CharField(max_length=150)
Expand All @@ -89,8 +88,7 @@ class AbstractUser(_ModelWithMeta, AbstractBaseUser, PermissionsMixin):
EMAIL_FIELD: str
USERNAME_FIELD: str

class Meta:
abstract: Literal[True]
Meta: ClassVar[type[_ModelMeta]]

def get_full_name(self) -> str: ...
def get_short_name(self) -> str: ...
Expand Down
18 changes: 5 additions & 13 deletions django-stubs/contrib/gis/db/backends/oracle/models.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,29 @@ from django.contrib.gis.db.backends.base.models import SpatialRefSysMixin
from django.db.models.manager import Manager
from typing_extensions import Self

from django_stubs_ext.db.models import ModelWithMeta as _ModelWithMeta
from django_stubs_ext.db.models import ModelMeta as _ModelMeta

class OracleGeometryColumns(_ModelWithMeta, models.Model):
class OracleGeometryColumns(models.Model):
table_name: Any
column_name: Any
srid: Any
objects: ClassVar[Manager[Self]]

class Meta:
app_label: str
db_table: str
managed: bool
Meta: ClassVar[type[_ModelMeta]]

@classmethod
def table_name_col(cls) -> Any: ...
@classmethod
def geom_col_name(cls) -> Any: ...

class OracleSpatialRefSys(_ModelWithMeta, models.Model, SpatialRefSysMixin):
class OracleSpatialRefSys(models.Model, SpatialRefSysMixin):
cs_name: Any
srid: Any
auth_srid: Any
auth_name: Any
wktext: Any
cs_bounds: Any
objects: ClassVar[Manager[Self]]

class Meta:
app_label: str
db_table: str
managed: bool
Meta: ClassVar[type[_ModelMeta]]

@property
def wkt(self) -> Any: ...
18 changes: 5 additions & 13 deletions django-stubs/contrib/gis/db/backends/postgis/models.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ from django.contrib.gis.db.backends.base.models import SpatialRefSysMixin
from django.db import models
from typing_extensions import Self

from django_stubs_ext.db.models import ModelWithMeta as _ModelWithMeta
from django_stubs_ext.db.models import ModelMeta as _ModelMeta

class PostGISGeometryColumns(_ModelWithMeta, models.Model):
class PostGISGeometryColumns(models.Model):
f_table_catalog: Any
f_table_schema: Any
f_table_name: Any
Expand All @@ -15,29 +15,21 @@ class PostGISGeometryColumns(_ModelWithMeta, models.Model):
srid: Any
type: Any
objects: ClassVar[models.Manager[Self]]

class Meta:
app_label: str
db_table: str
managed: bool
Meta: ClassVar[type[_ModelMeta]]

@classmethod
def table_name_col(cls) -> Any: ...
@classmethod
def geom_col_name(cls) -> Any: ...

class PostGISSpatialRefSys(_ModelWithMeta, models.Model, SpatialRefSysMixin):
class PostGISSpatialRefSys(models.Model, SpatialRefSysMixin):
srid: Any
auth_name: Any
auth_srid: Any
srtext: Any
proj4text: Any
objects: ClassVar[models.Manager[Self]]

class Meta:
app_label: str
db_table: str
managed: bool
Meta: ClassVar[type[_ModelMeta]]

@property
def wkt(self) -> Any: ...

0 comments on commit 4232c7e

Please sign in to comment.