Compare commits

...

2 Commits

Author SHA1 Message Date
Ethan Furman f7dca9b9c8
[3.9] bpo-42727: [Enum] EnumMeta.__prepare__ now accepts **kwds (GH-23917). (GH-23926)
* [3.9] [Enum] EnumMeta.__prepare__ now accepts **kwds (GH-23917).
(cherry picked from commit 6ec0adefad)
2020-12-24 12:02:38 -08:00
Miss Islington (bot) 3bb85672bb
closes bpo-42726: gdb libpython: InstanceProxy support for py3 (GH-23912)
On Fedora 31 gdb is using python 3.7.9, calling `proxyval` on an instance with a dictionary fails because of the `dict.iteritems` usage. This PR changes the code to be compatible with py2 and py3.

This changed seemed small enough to not need an issue and news blurb, if one is required please let me know.

Automerge-Triggered-By: GH:benjaminp
(cherry picked from commit b57ada98da)

Co-authored-by: Augusto Hack <hack.augusto@gmail.com>
2020-12-24 09:37:07 -08:00
5 changed files with 17 additions and 3 deletions

View File

@ -170,7 +170,7 @@ class EnumMeta(type):
Metaclass for Enum
"""
@classmethod
def __prepare__(metacls, cls, bases):
def __prepare__(metacls, cls, bases, **kwds):
# check that previous enum members do not exist
metacls._check_for_existing_members(cls, bases)
# create the namespace dict

View File

@ -2065,7 +2065,7 @@ class TestEnum(unittest.TestCase):
except ValueError:
pass
def test_init_subclass(self):
def test_init_subclass_calling(self):
class MyEnum(Enum):
def __init_subclass__(cls, **kwds):
super(MyEnum, cls).__init_subclass__(**kwds)
@ -2101,6 +2101,16 @@ class TestEnum(unittest.TestCase):
self.assertFalse(NeverEnum.__dict__.get('_test1', False))
self.assertFalse(NeverEnum.__dict__.get('_test2', False))
def test_init_subclass_parameter(self):
class multiEnum(Enum):
def __init_subclass__(cls, multi):
for member in cls:
member._as_parameter_ = multi * member.value
class E(multiEnum, multi=3):
A = 1
B = 2
self.assertEqual(E.A._as_parameter_, 3)
self.assertEqual(E.B._as_parameter_, 6)
class TestOrder(unittest.TestCase):

View File

@ -0,0 +1,2 @@
`EnumMeta.__prepare__` now accepts `**kwds` to properly support
`__init_subclass__`

View File

@ -0,0 +1,2 @@
Fixed Python 3 compatibility issue with gdb/libpython.py handling of attribute
dictionaries.

View File

@ -468,7 +468,7 @@ class InstanceProxy(object):
def __repr__(self):
if isinstance(self.attrdict, dict):
kwargs = ', '.join(["%s=%r" % (arg, val)
for arg, val in self.attrdict.iteritems()])
for arg, val in self.attrdict.items()])
return '<%s(%s) at remote 0x%x>' % (self.cl_name,
kwargs, self.address)
else: