Skip to content

Commit e4a75f6

Browse files
authored
Merge branch 'main' into fix/adjacency-discard-annotation-typing
2 parents 4c83bc9 + 1723666 commit e4a75f6

22 files changed

Lines changed: 7715 additions & 4557 deletions

File tree

‎cuda_bindings/cuda/bindings/_internal/_fast_enum.py‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44

5-
# CYTHON-BINDINGS-GENERATED-DO-NOT-MODIFY-THIS-FILE: format=1; content-sha256=581469c1fadb5f72c43b478d73f2b905562136c8723a25e2f4240b5b681e2894
5+
# CYTHON-BINDINGS-GENERATED-DO-NOT-MODIFY-THIS-FILE: format=1; content-sha256=35d522fae601127f3ffc9d0de45d9adf2572934ee3308f5d99567aa8efd5ae77
66
"""
77
This is a replacement for the stdlib enum.IntEnum.
88
@@ -33,10 +33,14 @@ def __init__(cls, name, bases, namespace):
3333
else:
3434
continue
3535

36-
singleton = int.__new__(cls, value)
37-
singleton.__doc__ = doc
38-
singleton._name = name
39-
cls.__singletons__[value] = singleton
36+
# A name sharing a value with an already-processed member is an
37+
# alias (e.g. a deprecated name kept for backward compatibility):
38+
# it resolves to the same singleton, but isn't a distinct member.
39+
if (singleton := cls.__singletons__.get(value)) is None:
40+
singleton = int.__new__(cls, value)
41+
singleton.__doc__ = doc
42+
singleton._name = name
43+
cls.__singletons__[value] = singleton
4044
cls.__members__[name] = singleton
4145

4246
for name, member in cls.__members__.items():
@@ -46,10 +50,10 @@ def __repr__(cls) -> str:
4650
return f"<enum '{cls.__name__}'>"
4751

4852
def __len__(cls) -> int:
49-
return len(cls.__members__)
53+
return len(cls.__singletons__)
5054

5155
def __iter__(cls) -> Iterator["FastEnum"]:
52-
return iter(cls.__members__.values())
56+
return iter(cls.__singletons__.values())
5357

5458
def __contains__(cls, item: Any) -> bool:
5559
return item in cls.__singletons__

0 commit comments

Comments
 (0)