Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8d8efe7

Browse files
[3.11] gh-112316: Improve docs of inspect.signature and Signature.from_callable (#112317) (#112630)
(cherry-picked from commit a74daba) Co-authored-by: Nikita Sobolev <[email protected]>
1 parent 720f5bf commit 8d8efe7

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

Doc/library/inspect.rst

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ function.
599599

600600
.. function:: signature(callable, *, follow_wrapped=True, globals=None, locals=None, eval_str=False)
601601

602-
Return a :class:`Signature` object for the given ``callable``::
602+
Return a :class:`Signature` object for the given *callable*::
603603

604604
>>> from inspect import signature
605605
>>> def foo(a, *, b:int, **kwargs):
@@ -625,29 +625,30 @@ function.
625625
For objects defined in modules using stringized annotations
626626
(``from __future__ import annotations``), :func:`signature` will
627627
attempt to automatically un-stringize the annotations using
628-
:func:`inspect.get_annotations()`. The
629-
``global``, ``locals``, and ``eval_str`` parameters are passed
630-
into :func:`inspect.get_annotations()` when resolving the
631-
annotations; see the documentation for :func:`inspect.get_annotations()`
628+
:func:`get_annotations`. The
629+
*global*, *locals*, and *eval_str* parameters are passed
630+
into :func:`get_annotations` when resolving the
631+
annotations; see the documentation for :func:`get_annotations`
632632
for instructions on how to use these parameters.
633633

634634
Raises :exc:`ValueError` if no signature can be provided, and
635635
:exc:`TypeError` if that type of object is not supported. Also,
636-
if the annotations are stringized, and ``eval_str`` is not false,
637-
the ``eval()`` call(s) to un-stringize the annotations could
638-
potentially raise any kind of exception.
636+
if the annotations are stringized, and *eval_str* is not false,
637+
the ``eval()`` call(s) to un-stringize the annotations in :func:`get_annotations`
638+
could potentially raise any kind of exception.
639639

640640
A slash(/) in the signature of a function denotes that the parameters prior
641641
to it are positional-only. For more info, see
642642
:ref:`the FAQ entry on positional-only parameters <faq-positional-only-arguments>`.
643643

644-
.. versionadded:: 3.5
645-
``follow_wrapped`` parameter. Pass ``False`` to get a signature of
646-
``callable`` specifically (``callable.__wrapped__`` will not be used to
644+
.. versionchanged:: 3.5
645+
The *follow_wrapped* parameter was added.
646+
Pass ``False`` to get a signature of
647+
*callable* specifically (``callable.__wrapped__`` will not be used to
647648
unwrap decorated callables.)
648649

649-
.. versionadded:: 3.10
650-
``globals``, ``locals``, and ``eval_str`` parameters.
650+
.. versionchanged:: 3.10
651+
The *globals*, *locals*, and *eval_str* parameters were added.
651652

652653
.. note::
653654

@@ -727,12 +728,10 @@ function.
727728
>>> str(new_sig)
728729
"(a, b) -> 'new return anno'"
729730

730-
.. classmethod:: Signature.from_callable(obj, *, follow_wrapped=True, globalns=None, localns=None)
731+
.. classmethod:: Signature.from_callable(obj, *, follow_wrapped=True, globals=None, locals=None, eval_str=False)
731732

732733
Return a :class:`Signature` (or its subclass) object for a given callable
733-
``obj``. Pass ``follow_wrapped=False`` to get a signature of ``obj``
734-
without unwrapping its ``__wrapped__`` chain. ``globalns`` and
735-
``localns`` will be used as the namespaces when resolving annotations.
734+
*obj*.
736735

737736
This method simplifies subclassing of :class:`Signature`::
738737

@@ -745,8 +744,8 @@ function.
745744

746745
.. versionadded:: 3.5
747746

748-
.. versionadded:: 3.10
749-
``globalns`` and ``localns`` parameters.
747+
.. versionchanged:: 3.10
748+
The *globals*, *locals*, and *eval_str* parameters were added.
750749

751750

752751
.. class:: Parameter(name, kind, *, default=Parameter.empty, annotation=Parameter.empty)

0 commit comments

Comments
 (0)