Skip to content

Commit 3e10d5b

Browse files
committed
enum.py: Rename list_members to list.
Signed-off-by: Ihor Nehrutsa <Ihor.Nehrutsa@gmail.com>
1 parent 28ac6ba commit 3e10d5b

2 files changed

Lines changed: 8 additions & 7 deletions

File tree

python-stdlib/enum/enum.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ The object representing a specific member of an Enum.
101101

102102
### `Enum`
103103
The base class for all enumerations.
104-
* `list_members()`: Returns a list of `(name, value)` tuples for all defined members.
104+
* `list()`: Returns a list of all defined members.
105105
* `is_value(value)`: Returns `True` if the provided raw value exists within the Enum.
106106
* `__len__`: Returns the total number of members.
107107
* `__iter__`: Allows looping through members (e.g., `[m.name for m in color_inst]`).

python-stdlib/enum/enum.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,17 @@ def _lookup(cls, value):
6767

6868
raise AttributeError(f"{value} is not in {cls.__name__}")
6969

70-
def list_members(self):
71-
# Returns a list of tuples (name, value) for all members
72-
return [(m.name, m.value) for m in self]
70+
def list(self):
71+
# Returns a list of all members
72+
return [member for member in self]
7373

7474
def _update(self, key, value):
7575
setattr(self.__class__, key, EnumValue(value, key))
7676

7777
def _scan_class_attrs(self):
7878
# Converts static class attributes into EnumValue objects
7979
# List of methods and internal names that should not be converted
80-
ignored = ('is_value', 'list_members')
80+
ignored = ('is_value', 'list')
8181
for key in dir(self.__class__):
8282
# Skip internal names and methods
8383
if key.startswith('_') or key in ignored:
@@ -93,7 +93,7 @@ def is_value(self, value):
9393

9494
def __repr__(self):
9595
# Supports the condition: obj == eval(repr(obj))
96-
members = {m.name: m.value for m in self}
96+
members = {member.name: member.value for member in self}
9797
if self.__class__.__name__ == 'Enum':
9898
return f"Enum(name='Enum', names={members})"
9999
# Return a string like: Name(names={'KEY1': VALUE1, 'KEY2': VALUE2, ..})
@@ -127,7 +127,7 @@ def __iter__(self):
127127
def __eq__(self, other):
128128
if not isinstance(other, Enum):
129129
return False
130-
return self.list_members() == other.list_members()
130+
return self.list() == other.list()
131131

132132

133133
if __name__ == '__main__':
@@ -140,6 +140,7 @@ class Color(Enum):
140140
# Create instance
141141
c = Color()
142142
print(f"Enum c: {c}")
143+
print("c.list():", c.list())
143144

144145
# Basic access
145146
print(f"RED: Name={c.RED.name}, Value={c.RED.value}, EnumValue={c.RED}, Call={c.RED()} ")

0 commit comments

Comments
 (0)