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

Skip to content

Commit a74daba

Browse files
gh-112316: Improve docs of inspect.signature and Signature.from_callable (#112317)
Co-authored-by: Alex Waygood <[email protected]>
1 parent 939fc6d commit a74daba

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
@@ -620,7 +620,7 @@ function.
620620

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

623-
Return a :class:`Signature` object for the given ``callable``::
623+
Return a :class:`Signature` object for the given *callable*::
624624

625625
>>> from inspect import signature
626626
>>> def foo(a, *, b:int, **kwargs):
@@ -646,29 +646,30 @@ function.
646646
For objects defined in modules using stringized annotations
647647
(``from __future__ import annotations``), :func:`signature` will
648648
attempt to automatically un-stringize the annotations using
649-
:func:`inspect.get_annotations()`. The
650-
``global``, ``locals``, and ``eval_str`` parameters are passed
651-
into :func:`inspect.get_annotations()` when resolving the
652-
annotations; see the documentation for :func:`inspect.get_annotations()`
649+
:func:`get_annotations`. The
650+
*global*, *locals*, and *eval_str* parameters are passed
651+
into :func:`get_annotations` when resolving the
652+
annotations; see the documentation for :func:`get_annotations`
653653
for instructions on how to use these parameters.
654654

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

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

665-
.. versionadded:: 3.5
666-
``follow_wrapped`` parameter. Pass ``False`` to get a signature of
667-
``callable`` specifically (``callable.__wrapped__`` will not be used to
665+
.. versionchanged:: 3.5
666+
The *follow_wrapped* parameter was added.
667+
Pass ``False`` to get a signature of
668+
*callable* specifically (``callable.__wrapped__`` will not be used to
668669
unwrap decorated callables.)
669670

670-
.. versionadded:: 3.10
671-
``globals``, ``locals``, and ``eval_str`` parameters.
671+
.. versionchanged:: 3.10
672+
The *globals*, *locals*, and *eval_str* parameters were added.
672673

673674
.. note::
674675

@@ -752,12 +753,10 @@ function.
752753
Signature objects are also supported by generic function
753754
:func:`copy.replace`.
754755

755-
.. classmethod:: Signature.from_callable(obj, *, follow_wrapped=True, globalns=None, localns=None)
756+
.. classmethod:: Signature.from_callable(obj, *, follow_wrapped=True, globals=None, locals=None, eval_str=False)
756757

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

762761
This method simplifies subclassing of :class:`Signature`::
763762

@@ -770,8 +769,8 @@ function.
770769

771770
.. versionadded:: 3.5
772771

773-
.. versionadded:: 3.10
774-
``globalns`` and ``localns`` parameters.
772+
.. versionchanged:: 3.10
773+
The *globals*, *locals*, and *eval_str* parameters were added.
775774

776775

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

0 commit comments

Comments
 (0)