Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
268c20ef
Commit
268c20ef
authored
Apr 13, 2016
by
Ethan Furman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue26748: Enum classes should evaluate as True
parent
3c69bee1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
0 deletions
+19
-0
Lib/enum.py
Lib/enum.py
+6
-0
Lib/test/test_enum.py
Lib/test/test_enum.py
+13
-0
No files found.
Lib/enum.py
View file @
268c20ef
...
...
@@ -193,6 +193,12 @@ class EnumMeta(type):
enum_class
.
__new__
=
Enum
.
__new__
return
enum_class
def
__bool__
(
self
):
"""
classes/types should always be True.
"""
return
True
def
__call__
(
cls
,
value
,
names
=
None
,
*
,
module
=
None
,
qualname
=
None
,
type
=
None
):
"""Either returns an existing member, or creates a new enum class.
...
...
Lib/test/test_enum.py
View file @
268c20ef
...
...
@@ -257,6 +257,19 @@ class TestEnum(unittest.TestCase):
with
self
.
assertRaises
(
AttributeError
):
del
Season
.
SPRING
.
name
def
test_bool_of_class
(
self
):
class
Empty
(
Enum
):
pass
self
.
assertTrue
(
bool
(
Empty
))
def
test_bool_of_member
(
self
):
class
Count
(
Enum
):
zero
=
0
one
=
1
two
=
2
for
member
in
Count
:
self
.
assertTrue
(
bool
(
member
))
def
test_invalid_names
(
self
):
with
self
.
assertRaises
(
ValueError
):
class
Wrong
(
Enum
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment