Skip to content

Commit 456cc1f

Browse files
soreavismiss-islington
authored andcommitted
gh-62534: Document that three-argument type() does not call __prepare__ (GH-154028)
The three-argument form of type() skips the metaclass __prepare__ method, which is called by the class statement machinery rather than by the metaclass call itself. Say so in the type() entry and point to types.new_class() for dynamic class creation with the appropriate metaclass, as directed in the issue thread. (cherry picked from commit 5625b18) Co-authored-by: soreavis <263610811+soreavis@users.noreply.github.com>
1 parent 6a9c478 commit 456cc1f

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

Doc/library/functions.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2091,6 +2091,11 @@ are always available. They are listed here in alphabetical order.
20912091
in the same way that keywords in a class
20922092
definition (besides *metaclass*) would.
20932093

2094+
Unlike a :keyword:`class` statement, the three argument form does not
2095+
call the metaclass ``__prepare__`` method (see :ref:`prepare`). Use
2096+
:func:`types.new_class` to dynamically create a class using the
2097+
appropriate metaclass.
2098+
20942099
See also :ref:`class-customization`.
20952100

20962101
.. versionchanged:: 3.6

0 commit comments

Comments
 (0)