From a136ca8cc5eeb25a031aa33a1e18eab8bead6061 Mon Sep 17 00:00:00 2001 From: Shantanu Jain Date: Tue, 29 Oct 2024 17:37:21 -0700 Subject: [PATCH 1/2] Update enums to reflect typing spec changes See https://typing.readthedocs.io/en/latest/spec/enums.html#defining-members https://github.com/python/typing-council/issues/11 The next version of mypy will obey the spec change: https://github.com/python/mypy/pull/18068 pyright already requires this --- django-stubs/contrib/admin/options.pyi | 8 ++++---- django-stubs/contrib/gis/gdal/srs.pyi | 6 +++--- django-stubs/db/models/constants.pyi | 5 +++-- django-stubs/db/models/constraints.pyi | 6 +++--- django-stubs/template/base.pyi | 10 +++++----- 5 files changed, 18 insertions(+), 17 deletions(-) diff --git a/django-stubs/contrib/admin/options.pyi b/django-stubs/contrib/admin/options.pyi index 3a5ca8ab8..e4a98589a 100644 --- a/django-stubs/contrib/admin/options.pyi +++ b/django-stubs/contrib/admin/options.pyi @@ -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 @@ -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: ... diff --git a/django-stubs/contrib/gis/gdal/srs.pyi b/django-stubs/contrib/gis/gdal/srs.pyi index f43fab0da..0fb47286e 100644 --- a/django-stubs/contrib/gis/gdal/srs.pyi +++ b/django-stubs/contrib/gis/gdal/srs.pyi @@ -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 diff --git a/django-stubs/db/models/constants.pyi b/django-stubs/db/models/constants.pyi index 14fc6195e..72ae7cdc6 100644 --- a/django-stubs/db/models/constants.pyi +++ b/django-stubs/db/models/constants.pyi @@ -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, ...) diff --git a/django-stubs/db/models/constraints.pyi b/django-stubs/db/models/constraints.pyi index 988f0f4b0..53a51e443 100644 --- a/django-stubs/db/models/constraints.pyi +++ b/django-stubs/db/models/constraints.pyi @@ -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 @@ -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 diff --git a/django-stubs/template/base.pyi b/django-stubs/template/base.pyi index fd4d2dc4c..aaa99594c 100644 --- a/django-stubs/template/base.pyi +++ b/django-stubs/template/base.pyi @@ -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 @@ -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 From 0a28f2c648584c4ae3697431dc09957be815abf8 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 30 Oct 2024 00:37:57 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks --- django-stubs/db/models/constraints.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/django-stubs/db/models/constraints.pyi b/django-stubs/db/models/constraints.pyi index 53a51e443..e3dd59585 100644 --- a/django-stubs/db/models/constraints.pyi +++ b/django-stubs/db/models/constraints.pyi @@ -1,6 +1,6 @@ from collections.abc import Sequence from enum import Enum -from typing import Any, overload, cast +from typing import Any, cast, overload from django.db.backends.base.schema import BaseDatabaseSchemaEditor from django.db.models.base import Model