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

Skip to content

gh-120361: Add nonmember test with enum flags inside to test_enum #120364

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 4 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed 8000 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
11 changes: 11 additions & 0 deletions Lib/test/test_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -1495,6 +1495,17 @@ 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)

def test_nested_classes_in_enum_with_member(self):
"""Support locally-defined nested classes."""
class Outer(Enum):
Expand Down
0