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
cd45385f
Commit
cd45385f
authored
Oct 05, 2018
by
Ethan Furman
Committed by
GitHub
Oct 05, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-34909: keep searching mixins until base class is found (GH-9737)
parent
92878829
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
3 deletions
+22
-3
Lib/enum.py
Lib/enum.py
+1
-3
Lib/test/test_enum.py
Lib/test/test_enum.py
+21
-0
No files found.
Lib/enum.py
View file @
cd45385f
...
@@ -486,7 +486,7 @@ class EnumMeta(type):
...
@@ -486,7 +486,7 @@ class EnumMeta(type):
if
base
is
object
:
if
base
is
object
:
continue
continue
elif
'__new__'
in
base
.
__dict__
:
elif
'__new__'
in
base
.
__dict__
:
if
issubclass
(
base
,
Enum
)
and
not
hasattr
(
base
,
'__new_member__'
)
:
if
issubclass
(
base
,
Enum
):
continue
continue
return
base
return
base
...
@@ -499,7 +499,6 @@ class EnumMeta(type):
...
@@ -499,7 +499,6 @@ class EnumMeta(type):
member_type
=
_find_data_type
(
bases
)
or
object
member_type
=
_find_data_type
(
bases
)
or
object
if
first_enum
.
_member_names_
:
if
first_enum
.
_member_names_
:
raise
TypeError
(
"Cannot extend enumerations"
)
raise
TypeError
(
"Cannot extend enumerations"
)
return
member_type
,
first_enum
return
member_type
,
first_enum
@
staticmethod
@
staticmethod
...
@@ -545,7 +544,6 @@ class EnumMeta(type):
...
@@ -545,7 +544,6 @@ class EnumMeta(type):
use_args
=
False
use_args
=
False
else
:
else
:
use_args
=
True
use_args
=
True
return
__new__
,
save_new
,
use_args
return
__new__
,
save_new
,
use_args
...
...
Lib/test/test_enum.py
View file @
cd45385f
...
@@ -1842,6 +1842,27 @@ class TestEnum(unittest.TestCase):
...
@@ -1842,6 +1842,27 @@ class TestEnum(unittest.TestCase):
self
.
assertEqual
(
ConfusedColor
.
RED
.
social
(),
"what's up?"
)
self
.
assertEqual
(
ConfusedColor
.
RED
.
social
(),
"what's up?"
)
self
.
assertTrue
(
issubclass
(
ReformedColor
,
int
))
self
.
assertTrue
(
issubclass
(
ReformedColor
,
int
))
def
test_multiple_inherited_mixin
(
self
):
class
StrEnum
(
str
,
Enum
):
def
__new__
(
cls
,
*
args
,
**
kwargs
):
for
a
in
args
:
if
not
isinstance
(
a
,
str
):
raise
TypeError
(
"Enumeration '%s' (%s) is not"
" a string"
%
(
a
,
type
(
a
).
__name__
))
return
str
.
__new__
(
cls
,
*
args
,
**
kwargs
)
@
unique
class
Decision1
(
StrEnum
):
REVERT
=
"REVERT"
REVERT_ALL
=
"REVERT_ALL"
RETRY
=
"RETRY"
class
MyEnum
(
StrEnum
):
pass
@
unique
class
Decision2
(
MyEnum
):
REVERT
=
"REVERT"
REVERT_ALL
=
"REVERT_ALL"
RETRY
=
"RETRY"
class
TestOrder
(
unittest
.
TestCase
):
class
TestOrder
(
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