update enum.py; add blurb; update WHATSNEW

This commit is contained in:
Ethan Furman 2020-12-28 21:55:02 -08:00
parent 65ed6ec6c2
commit 83ac508bbd
3 changed files with 10 additions and 15 deletions

View File

@ -62,6 +62,11 @@ Summary -- Release highlights
.. This section singles out the most important changes in Python 3.10.
Brevity is key.
The methods :func:`__init_subclass__` and :func:`__set_name__`, introduced
in :pep:`487`, have been moved from :func:`type.__new__` to
:func:`type.__init__`. This ensures that custome metaclasses are able to
finish creating a class before those two methods are called.
.. PEP-sized items next.

View File

@ -230,19 +230,8 @@ class EnumMeta(type):
# postpone calling __init_subclass__
if '__init_subclass__' in classdict and classdict['__init_subclass__'] is None:
raise TypeError('%s.__init_subclass__ cannot be None')
# remove current __init_subclass__ so previous one can be found with getattr
# new_init_subclass = classdict.pop('__init_subclass__', None)
# create our new Enum type
if bases:
# bases = (_NoInitSubclass, ) + bases
enum_class = super().__new__(metacls, cls, bases, classdict, **kwds)
# enum_class.__bases__ = enum_class.__bases__[1:] #or (object, )
else:
enum_class = super().__new__(metacls, cls, bases, classdict, **kwds)
# old_init_subclass = getattr(enum_class, '__init_subclass__', None)
# and restore the new one (if there was one)
# if new_init_subclass is not None:
# enum_class.__init_subclass__ = classmethod(new_init_subclass)
enum_class = super().__new__(metacls, cls, bases, classdict, **kwds)
enum_class._member_names_ = [] # names in definition order
enum_class._member_map_ = {} # name->value map
enum_class._member_type_ = member_type
@ -354,9 +343,6 @@ class EnumMeta(type):
if _order_ != enum_class._member_names_:
raise TypeError('member order does not match _order_')
# finally, call parents' __init_subclass__
# if Enum is not None and old_init_subclass is not None:
# old_init_subclass(**kwds)
return enum_class
def __bool__(self):

View File

@ -0,0 +1,4 @@
Move the calls to ``__init_subclass__`` and ``__set_name__`` from
``type.__new__`` to ``type.__init__``. This ensures that custom metaclasses
are able to completely finish creating a class before the
``__init_subclass__`` and ``__set_name__`` methods are run.