From 456cc1fede445cb3a8054e66238ebd125367d3f1 Mon Sep 17 00:00:00 2001 From: soreavis <263610811+soreavis@users.noreply.github.com> Date: Sun, 19 Jul 2026 17:31:59 +0200 Subject: [PATCH] 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 5625b187ab528e10dcaa21726a7c95b110d97190) Co-authored-by: soreavis <263610811+soreavis@users.noreply.github.com> --- Doc/library/functions.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst index e7655449154a185..a42d0f338577f52 100644 --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -2091,6 +2091,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