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
b41803e3
Commit
b41803e3
authored
Jul 25, 2013
by
Ethan Furman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Close #18545: now only executes member_type if no _value_ is assigned in __new__.
parent
4d35e75c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
4 deletions
+20
-4
Lib/enum.py
Lib/enum.py
+4
-4
Lib/test/test_enum.py
Lib/test/test_enum.py
+16
-0
No files found.
Lib/enum.py
View file @
b41803e3
...
...
@@ -152,12 +152,12 @@ class EnumMeta(type):
args
=
(
args
,
)
# wrap it one more time
if
not
use_args
:
enum_member
=
__new__
(
enum_class
)
original_value
=
value
if
not
hasattr
(
enum_member
,
'_value_'
):
enum_member
.
_value_
=
value
else
:
enum_member
=
__new__
(
enum_class
,
*
args
)
original_value
=
member_type
(
*
args
)
if
not
hasattr
(
enum_member
,
'_value_'
):
enum_member
.
_value_
=
original_value
enum_member
.
_value_
=
member_type
(
*
args
)
value
=
enum_member
.
_value_
enum_member
.
_member_type_
=
member_type
enum_member
.
_name_
=
member_name
...
...
Lib/test/test_enum.py
View file @
b41803e3
...
...
@@ -934,6 +934,22 @@ class TestEnum(unittest.TestCase):
self
.
assertEqual
(
ColorInAList
.
red
.
value
,
[
1
])
self
.
assertEqual
(
ColorInAList
([
1
]),
ColorInAList
.
red
)
def
test_conflicting_types_resolved_in_new
(
self
):
class
LabelledIntEnum
(
int
,
Enum
):
def
__new__
(
cls
,
*
args
):
value
,
label
=
args
obj
=
int
.
__new__
(
cls
,
value
)
obj
.
label
=
label
obj
.
_value_
=
value
return
obj
class
LabelledList
(
LabelledIntEnum
):
unprocessed
=
(
1
,
"Unprocessed"
)
payment_complete
=
(
2
,
"Payment Complete"
)
self
.
assertEqual
(
list
(
LabelledList
),
[
LabelledList
.
unprocessed
,
LabelledList
.
payment_complete
])
self
.
assertEqual
(
LabelledList
.
unprocessed
,
1
)
self
.
assertEqual
(
LabelledList
(
1
),
LabelledList
.
unprocessed
)
class
TestUnique
(
unittest
.
TestCase
):
...
...
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