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:
Jelle Zijlstra 2022-04-16 09:01:43 -07:00 committed by GitHub
parent 9300b6d729
commit 055760ed9e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 133 additions and 4 deletions

View file

@ -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