[New-bugs-announce] [issue35158] Fix PEP 3115 to NOT imply that the class dictionary is used in the final created class
Joy Diamond
report at bugs.python.org
Sat Nov 3 20:07:33 EDT 2018
New submission from Joy Diamond <python.gem at gmail.com>:
Fix the following in https://www.python.org/dev/peps/pep-3115/
REPLACE:
"""
def __new__(cls, name, bases, classdict):
# Note that we replace the classdict with a regular
# dict before passing it to the superclass, so that we
# don't continue to record member names after the class
# has been created.
result = type.__new__(cls, name, bases, dict(classdict))
result.member_names = classdict.member_names
return result
"""
WITH:
"""
def __new__(cls, name, bases, classdict):
result = type.__new__(cls, name, bases, classdict)
result.member_names = classdict.member_names
return result
"""
REMOVING the incorrect comment & copying of `classdict`
According to: https://docs.python.org/3/reference/datamodel.html#preparing-the-class-namespace
"When a new class is created by type.__new__, the object provided as the namespace parameter is copied to a new ordered mapping and the original object is discarded."
Hence there is no need to copy `classdict`
----------
messages: 329213
nosy: joydiamond
priority: normal
severity: normal
status: open
title: Fix PEP 3115 to NOT imply that the class dictionary is used in the final created class
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue35158>
_______________________________________
More information about the New-bugs-announce
mailing list