mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
gh-89263: Add typing.get_overloads (GH-31716)
Based on suggestions by Guido van Rossum, Spencer Brown, and Alex Waygood. Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com> Co-authored-by: Guido van Rossum <gvanrossum@gmail.com> Co-authored-by: Ken Jin <kenjin4096@gmail.com>
This commit is contained in:
parent
9300b6d729
commit
055760ed9e
4 changed files with 133 additions and 4 deletions
|
@ -2407,6 +2407,35 @@ Functions and decorators
|
|||
|
||||
See :pep:`484` for details and comparison with other typing semantics.
|
||||
|
||||
.. versionchanged:: 3.11
|
||||
Overloaded functions can now be introspected at runtime using
|
||||
:func:`get_overloads`.
|
||||
|
||||
|
||||
.. function:: get_overloads(func)
|
||||
|
||||
Return a sequence of :func:`@overload <overload>`-decorated definitions for
|
||||
*func*. *func* is the function object for the implementation of the
|
||||
overloaded function. For example, given the definition of ``process`` in
|
||||
the documentation for :func:`@overload <overload>`,
|
||||
``get_overloads(process)`` will return a sequence of three function objects
|
||||
for the three defined overloads. If called on a function with no overloads,
|
||||
``get_overloads`` returns an empty sequence.
|
||||
|
||||
``get_overloads`` can be used for introspecting an overloaded function at
|
||||
runtime.
|
||||
|
||||
.. versionadded:: 3.11
|
||||
|
||||
|
||||
.. function:: clear_overloads()
|
||||
|
||||
Clear all registered overloads in the internal registry. This can be used
|
||||
to reclaim the memory used by the registry.
|
||||
|
||||
.. versionadded:: 3.11
|
||||
|
||||
|
||||
.. decorator:: final
|
||||
|
||||
A decorator to indicate to type checkers that the decorated method
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue