Skip to content

Commit 5625b18

Browse files
authored
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.
1 parent eb44708 commit 5625b18

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
@@ -2179,6 +2179,11 @@ are always available. They are listed here in alphabetical order.
21792179
in the same way that keywords in a class
21802180
definition (besides *metaclass*) would.
21812181

2182+
Unlike a :keyword:`class` statement, the three argument form does not
2183+
call the metaclass ``__prepare__`` method (see :ref:`prepare`). Use
2184+
:func:`types.new_class` to dynamically create a class using the
2185+
appropriate metaclass.
2186+
21822187
See also :ref:`class-customization`.
21832188

21842189
.. versionchanged:: 3.6

0 commit comments

Comments
 (0)