From bf7bb77ebe4e7b6102d727eca5b049c250126970 Mon Sep 17 00:00:00 2001 From: Gouvernathor <44340603+Gouvernathor@users.noreply.github.com> Date: Thu, 29 Feb 2024 15:48:10 +0100 Subject: [PATCH] Re-document __signature__ as a feature --- Doc/library/inspect.rst | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/Doc/library/inspect.rst b/Doc/library/inspect.rst index ed8d705da3b0b5..41171ff9b9ae24 100644 --- a/Doc/library/inspect.rst +++ b/Doc/library/inspect.rst @@ -665,6 +665,16 @@ function. Accepts a wide range of Python callables, from plain functions and classes to :func:`functools.partial` objects. + If the passed object has a :attr:`!__signature__` attribute containing + an instance of :class:`Signature`, this function returns it. + If the attribute contains None, it is ignored. + + .. impl-detail:: + + The behavior when the :attr:`!__signature__` attribute contains a value of + any other type is an implementation detail and subject to + unannounced changes. Consult the source code for current semantics. + For objects defined in modules using stringized annotations (``from __future__ import annotations``), :func:`signature` will attempt to automatically un-stringize the annotations using @@ -699,13 +709,6 @@ function. Python. For example, in CPython, some built-in functions defined in C provide no metadata about their arguments. - .. impl-detail:: - - If the passed object has a :attr:`!__signature__` attribute, - we may use it to create the signature. - The exact semantics are an implementation detail and are subject to - unannounced changes. Consult the source code for current semantics. - .. class:: Signature(parameters=None, *, return_annotation=Signature.empty)