Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3bad04c

Browse files
committed
Merge: #26829: Clarify that namespace is copied to a new __dict__ in instance creation.
2 parents 1b50c4d + dd4fcf5 commit 3bad04c

3 files changed

Lines changed: 9 additions & 2 deletions

File tree

Doc/library/functions.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,8 +1449,9 @@ are always available. They are listed here in alphabetical order.
14491449
class name and becomes the :attr:`~class.__name__` attribute; the *bases*
14501450
tuple itemizes the base classes and becomes the :attr:`~class.__bases__`
14511451
attribute; and the *dict* dictionary is the namespace containing definitions
1452-
for class body and becomes the :attr:`~object.__dict__` attribute. For
1453-
example, the following two statements create identical :class:`type` objects:
1452+
for class body and is copied to a standard dictionary to become the
1453+
:attr:`~object.__dict__` attribute. For example, the following two
1454+
statements create identical :class:`type` objects:
14541455

14551456
>>> class X:
14561457
... a = 1

Doc/reference/datamodel.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1735,6 +1735,11 @@ After the class object is created, it is passed to the class decorators
17351735
included in the class definition (if any) and the resulting object is bound
17361736
in the local namespace as the defined class.
17371737

1738+
When a new class is created by ``type.__new__``, the object provided as the
1739+
namespace parameter is copied to a standard Python dictionary and the original
1740+
object is discarded. The new copy becomes the :attr:`~object.__dict__` attribute
1741+
of the class object.
1742+
17381743
.. seealso::
17391744

17401745
:pep:`3135` - New super

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,6 +1007,7 @@ Peter Moody
10071007
Paul Moore
10081008
Ross Moore
10091009
Ben Morgan
1010+
Emily Morehouse
10101011
Derek Morr
10111012
James A Morrison
10121013
Martin Morrison

0 commit comments

Comments
 (0)