Skip to content

Commit

Permalink
fix: py.typed
Browse files Browse the repository at this point in the history
  • Loading branch information
Ravencentric committed Nov 22, 2024
1 parent facdc03 commit e1a984d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
11 changes: 6 additions & 5 deletions src/stringenum/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
from typing_extensions import Self

if sys.version_info >= (3, 12): # pragma: no cover
from enum import EnumType, StrEnum
from enum import EnumMeta, StrEnum
else:
from enum import Enum, EnumMeta
from enum import Enum
from enum import EnumMeta as _EnumMeta

class EnumType(EnumMeta):
class EnumMeta(_EnumMeta):
# __contains__ was updated in 3.12 to no longer raise TypeError
# https://docs.python.org/3/library/enum.html#enum.EnumType.__contains__
# https://github.com/python/cpython/blob/09c240f20c47db126ad7e162df41e5c2596962d4/Lib/enum.py#L736-L751
Expand All @@ -26,7 +27,7 @@ def __contains__(cls: type[Any], value: object) -> bool:
return False

# https://github.com/python/cpython/blob/09c240f20c47db126ad7e162df41e5c2596962d4/Lib/enum.py#L1352-L1383
class StrEnum(str, Enum, metaclass=EnumType):
class StrEnum(str, Enum, metaclass=EnumMeta):
"""Enum where members are also (and must be) strings."""

def __new__(cls, *values: str) -> Self:
Expand Down Expand Up @@ -61,4 +62,4 @@ def _generate_next_value_(name: str, start: int, count: int, last_values: list[s
return name.lower()


__all__ = ("EnumType", "StrEnum")
__all__ = ("EnumMeta", "StrEnum")
10 changes: 5 additions & 5 deletions src/stringenum/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

from typing import TYPE_CHECKING

from stringenum._compat import EnumType, StrEnum
from stringenum._compat import EnumMeta, StrEnum

if TYPE_CHECKING:
from typing import TypeVar

from typing_extensions import Self

T = TypeVar("T", bound=EnumType)
T = TypeVar("T", bound=EnumMeta)


class DuplicateFreeStrEnum(StrEnum):
Expand All @@ -31,7 +31,7 @@ def __init__(self, *args: object) -> None:
raise ValueError(msg)


class _CaseInsensitiveGetItemAndContains(EnumType):
class _CaseInsensitiveGetItemAndContains(EnumMeta):
def __contains__(self: type[T], value: object) -> bool: # type: ignore[misc]
if isinstance(value, self):
return True
Expand Down Expand Up @@ -64,7 +64,7 @@ def _missing_(cls, value: object) -> Self:
raise ValueError(msg)


class _DoubleSidedGetItemAndContains(EnumType):
class _DoubleSidedGetItemAndContains(EnumMeta):
def __contains__(self: type[T], value: object) -> bool: # type: ignore[misc]
if isinstance(value, self):
return True
Expand Down Expand Up @@ -102,7 +102,7 @@ def _missing_(cls, value: object) -> Self:
raise ValueError(msg)


class _DoubleSidedCaseInsensitiveGetItemAndContains(EnumType):
class _DoubleSidedCaseInsensitiveGetItemAndContains(EnumMeta):
def __contains__(self: type[T], value: object) -> bool: # type: ignore[misc]
if isinstance(value, self):
return True
Expand Down
Empty file added src/stringenum/py.typed
Empty file.

0 comments on commit e1a984d

Please sign in to comment.