Skip to content

Commit a524c02

Browse files
committed
Enum
1 parent eebcad8 commit a524c02

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

README.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -677,14 +677,13 @@ random_member = random.choice(list(<enum>))
677677
Cutlery = Enum('Cutlery', ['knife', 'fork', 'spoon'])
678678
Cutlery = Enum('Cutlery', 'knife fork spoon')
679679
Cutlery = Enum('Cutlery', {'knife': 1, 'fork': 2, 'spoon': 3})
680+
```
680681

681-
# Functions can not be values, so they must be enclosed in tuple:
682-
LogicOp = Enum('LogicOp', {'AND': (lambda l, r: l and r, ),
683-
'OR' : (lambda l, r: l or r, )})
684-
685-
# But 'list(<enum>)' will only work if there is another value in the tuple:
686-
LogicOp = Enum('LogicOp', {'AND': (auto(), lambda l, r: l and r),
687-
'OR' : (auto(), lambda l, r: l or r)})
682+
```python
683+
# Functions can not be values, unless they are wrapped:
684+
from functools import partial
685+
LogicOp = Enum('LogicOp', {'AND': partial(lambda l, r: l and r),
686+
'OR' : partial(lambda l, r: l or r)})
688687
```
689688

690689

0 commit comments

Comments
 (0)