Skip to content

Commit b6c7313

Browse files
committed
Fix for enum types >= CPython 3.12
1 parent ab0863e commit b6c7313

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

dissect/cstruct/types/enum.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ def __getitem__(cls: type[_S], name: str | int) -> _S | Array:
7676

7777
__len__ = MetaType.__len__
7878

79-
if not PY_312:
80-
# Backport __contains__ from CPython 3.12
81-
def __contains__(cls, value: Any) -> bool:
82-
if isinstance(value, cls):
83-
return True
84-
return value in cls._value2member_map_
79+
def __contains__(cls, value: Any) -> bool:
80+
# We used to let stdlib enum handle `__containts``` but this commit is incompatible with our API:
81+
# https://github.com/python/cpython/commit/8a9aee71268c77867d3cc96d43cbbdcbe8c0e1e8
82+
if isinstance(value, cls):
83+
return True
84+
return value in cls._value2member_map_
8585

8686
def _read(cls, stream: BinaryIO, context: dict[str, Any] | None = None) -> Self:
8787
return cls(cls.type._read(stream, context))

0 commit comments

Comments
 (0)