Skip to content

Commit

Permalink
Update enums to reflect typing spec changes
Browse files Browse the repository at this point in the history
See https://typing.readthedocs.io/en/latest/spec/enums.html#defining-members

python/typing-council#11

The next version of mypy will obey the spec change: python/mypy#18068

pyright already requires this
  • Loading branch information
hauntsaninja committed Oct 30, 2024
1 parent da5d6f7 commit a136ca8
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 17 deletions.
8 changes: 4 additions & 4 deletions django-stubs/contrib/admin/options.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import enum
from collections.abc import Callable, Iterable, Iterator, Mapping, Sequence
from typing import Any, Generic, Literal, TypeVar, type_check_only
from typing import Any, Generic, Literal, TypeVar, cast, type_check_only

from django import forms
from django.contrib.admin.filters import FieldListFilter, ListFilter
Expand Down Expand Up @@ -45,9 +45,9 @@ VERTICAL: Literal[2]
_Direction: TypeAlias = Literal[1, 2]

class ShowFacets(enum.Enum):
NEVER: str
ALLOW: str
ALWAYS: str
NEVER = cast(str, ...)
ALLOW = cast(str, ...)
ALWAYS = cast(str, ...)

def get_content_type_for_model(obj: type[Model] | Model) -> ContentType: ...
def get_ul_class(radio_style: int) -> str: ...
Expand Down
6 changes: 3 additions & 3 deletions django-stubs/contrib/gis/gdal/srs.pyi
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from enum import IntEnum
from typing import Any, AnyStr
from typing import Any, AnyStr, cast

from django.contrib.gis.gdal.base import GDALBase
from typing_extensions import Self

class AxisOrder(IntEnum):
TRADITIONAL: int
AUTHORITY: int
TRADITIONAL = cast(int, ...)
AUTHORITY = cast(int, ...)

class SpatialReference(GDALBase):
destructor: Any
Expand Down
5 changes: 3 additions & 2 deletions django-stubs/db/models/constants.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from enum import Enum
from typing import cast

LOOKUP_SEP: str

class OnConflict(Enum):
IGNORE: str
UPDATE: str
IGNORE = cast(str, ...)
UPDATE = cast(str, ...)
6 changes: 3 additions & 3 deletions django-stubs/db/models/constraints.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from collections.abc import Sequence
from enum import Enum
from typing import Any, overload
from typing import Any, overload, cast

from django.db.backends.base.schema import BaseDatabaseSchemaEditor
from django.db.models.base import Model
Expand All @@ -10,8 +10,8 @@ from django.utils.functional import _StrOrPromise
from typing_extensions import Self, deprecated

class Deferrable(Enum):
DEFERRED: str
IMMEDIATE: str
DEFERRED = cast(str, ...)
IMMEDIATE = cast(str, ...)

class BaseConstraint:
name: str
Expand Down
10 changes: 5 additions & 5 deletions django-stubs/template/base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ from collections.abc import Callable, Iterable, Iterator, Mapping, Sequence
from enum import Enum
from logging import Logger
from re import Pattern
from typing import Any
from typing import Any, cast

from django.template.context import Context as Context # Django: imported for backwards compatibility
from django.template.engine import Engine
Expand All @@ -26,10 +26,10 @@ tag_re: Pattern[str]
logger: Logger

class TokenType(Enum):
TEXT: int
VAR: int
BLOCK: int
COMMENT: int
TEXT = cast(int, ...)
VAR = cast(int, ...)
BLOCK = cast(int, ...)
COMMENT = cast(int, ...)

class VariableDoesNotExist(Exception):
msg: str
Expand Down

0 comments on commit a136ca8

Please sign in to comment.