]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-62534: Document that three-argument type() does not call __prepare__ (GH-154028)
authorsoreavis <263610811+soreavis@users.noreply.github.com>
Sun, 19 Jul 2026 15:31:59 +0000 (17:31 +0200)
committerGitHub <noreply@github.com>
Sun, 19 Jul 2026 15:31:59 +0000 (17:31 +0200)
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.

Doc/library/functions.rst

index 8dbebf7048b5835f8c25f0a9967e3211ff092d48..f45ab397e9369380837e4302e0c70e4d5df6cd2d 100644 (file)
@@ -2179,6 +2179,11 @@ are always available.  They are listed here in alphabetical order.
    in the same way that keywords in a class
    definition (besides *metaclass*) would.
 
+   Unlike a :keyword:`class` statement, the three argument form does not
+   call the metaclass ``__prepare__`` method (see :ref:`prepare`).  Use
+   :func:`types.new_class` to dynamically create a class using the
+   appropriate metaclass.
+
    See also :ref:`class-customization`.
 
    .. versionchanged:: 3.6