https://github.com/python/cpython/commit/7fadfd82ebf6ea90b38cb3f2a046a51f8601a205
commit: 7fadfd82ebf6ea90b38cb3f2a046a51f8601a205
branch: main
author: Nikita Sobolev <[email protected]>
committer: ethanfurman <[email protected]>
date: 2024-06-14T10:25:35-07:00
summary:
gh-120361: Add `nonmember` test with enum flags inside to `test_enum`
(GH-120364)
* gh-120361: Add `nonmember` test with enum flags inside to `test_enum`
files:
M Doc/library/enum.rst
M Lib/test/test_enum.py
diff --git a/Doc/library/enum.rst b/Doc/library/enum.rst
index 8c604c2347a547..9cf94e342dad28 100644
--- a/Doc/library/enum.rst
+++ b/Doc/library/enum.rst
@@ -527,7 +527,7 @@ Data Types
``Flag`` is the same as :class:`Enum`, but its members support the bitwise
operators ``&`` (*AND*), ``|`` (*OR*), ``^`` (*XOR*), and ``~`` (*INVERT*);
- the results of those operators are members of the enumeration.
+ the results of those operations are (aliases of) members of the enumeration.
.. method:: __contains__(self, value)
diff --git a/Lib/test/test_enum.py b/Lib/test/test_enum.py
index 529dfc62eff680..99fd16ba361e6f 100644
--- a/Lib/test/test_enum.py
+++ b/Lib/test/test_enum.py
@@ -1495,6 +1495,27 @@ class SpamEnum(Enum):
spam = nonmember(SpamEnumIsInner)
self.assertTrue(SpamEnum.spam is SpamEnumIsInner)
+ def test_using_members_as_nonmember(self):
+ class Example(Flag):
+ A = 1
+ B = 2
+ ALL = nonmember(A | B)
+
+ self.assertEqual(Example.A.value, 1)
+ self.assertEqual(Example.B.value, 2)
+ self.assertEqual(Example.ALL, 3)
+ self.assertIs(type(Example.ALL), int)
+
+ class Example(Flag):
+ A = auto()
+ B = auto()
+ ALL = nonmember(A | B)
+
+ self.assertEqual(Example.A.value, 1)
+ self.assertEqual(Example.B.value, 2)
+ self.assertEqual(Example.ALL, 3)
+ self.assertIs(type(Example.ALL), int)
+
def test_nested_classes_in_enum_with_member(self):
"""Support locally-defined nested classes."""
class Outer(Enum):
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]