8000 [3.13] gh-120361: Add `nonmember` test with enum flags inside to `test_enum` (GH-120364) by miss-islington · Pull Request #120511 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

[3.13] gh-120361: Add nonmember test with enum flags inside to test_enum (GH-120364) #120511

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Doc/library/enum.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
21 changes: 21 additions & 0 deletions Lib/test/test_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Loading
0