Skip to content

Commit a136ca8

Browse files
committed
Update enums to reflect typing spec changes
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
1 parent da5d6f7 commit a136ca8

File tree

5 files changed

+18
-17
lines changed

5 files changed

+18
-17
lines changed

django-stubs/contrib/admin/options.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import enum
22
from collections.abc import Callable, Iterable, Iterator, Mapping, Sequence
3-
from typing import Any, Generic, Literal, TypeVar, type_check_only
3+
from typing import Any, Generic, Literal, TypeVar, cast, type_check_only
44

55
from django import forms
66
from django.contrib.admin.filters import FieldListFilter, ListFilter
@@ -45,9 +45,9 @@ VERTICAL: Literal[2]
4545
_Direction: TypeAlias = Literal[1, 2]
4646

4747
class ShowFacets(enum.Enum):
48-
NEVER: str
49-
ALLOW: str
50-
ALWAYS: str
48+
NEVER = cast(str, ...)
49+
ALLOW = cast(str, ...)
50+
ALWAYS = cast(str, ...)
5151

5252
def get_content_type_for_model(obj: type[Model] | Model) -> ContentType: ...
5353
def get_ul_class(radio_style: int) -> str: ...

django-stubs/contrib/gis/gdal/srs.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
from enum import IntEnum
2-
from typing import Any, AnyStr
2+
from typing import Any, AnyStr, cast
33

44
from django.contrib.gis.gdal.base import GDALBase
55
from typing_extensions import Self
66

77
class AxisOrder(IntEnum):
8-
TRADITIONAL: int
9-
AUTHORITY: int
8+
TRADITIONAL = cast(int, ...)
9+
AUTHORITY = cast(int, ...)
1010

1111
class SpatialReference(GDALBase):
1212
destructor: Any

django-stubs/db/models/constants.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from enum import Enum
2+
from typing import cast
23

34
LOOKUP_SEP: str
45

56
class OnConflict(Enum):
6-
IGNORE: str
7-
UPDATE: str
7+
IGNORE = cast(str, ...)
8+
UPDATE = cast(str, ...)

django-stubs/db/models/constraints.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from collections.abc import Sequence
22
from enum import Enum
3-
from typing import Any, overload
3+
from typing import Any, overload, cast
44

55
from django.db.backends.base.schema import BaseDatabaseSchemaEditor
66
from django.db.models.base import Model
@@ -10,8 +10,8 @@ from django.utils.functional import _StrOrPromise
1010
from typing_extensions import Self, deprecated
1111

1212
class Deferrable(Enum):
13-
DEFERRED: str
14-
IMMEDIATE: str
13+
DEFERRED = cast(str, ...)
14+
IMMEDIATE = cast(str, ...)
1515

1616
class BaseConstraint:
1717
name: str

django-stubs/template/base.pyi

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ from collections.abc import Callable, Iterable, Iterator, Mapping, Sequence
22
from enum import Enum
33
from logging import Logger
44
from re import Pattern
5-
from typing import Any
5+
from typing import Any, cast
66

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

2828
class TokenType(Enum):
29-
TEXT: int
30-
VAR: int
31-
BLOCK: int
32-
COMMENT: int
29+
TEXT = cast(int, ...)
30+
VAR = cast(int, ...)
31+
BLOCK = cast(int, ...)
32+
COMMENT = cast(int, ...)
3333

3434
class VariableDoesNotExist(Exception):
3535
msg: str

0 commit comments

Comments
 (0)