-
-
Notifications
You must be signed in to change notification settings - Fork 32k
gh-89263: Add typing.get_overloads #31716
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2ee377d
831b565
f03f8a9
404668a
7a5b0d1
6998255
26bb908
f52b757
fc6a925
b524244
e95558e
31fd72d
7041ad3
e26b0db
1bf89fb
83ac432
dfdbdc7
e16c8d0
b3d2227
9727eee
2e374b8
ff03b12
17f0710
2346970
f2053a0
b6131ad
506bd66
e9a2100
2b1a5cc
103bfd4
d453f7f
450afeb
ea62287
905253c
debbf8a
754c134
1ad8224
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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 | ||||||
Comment on lines
+2418
to
+2419
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This sentence sounds quite strange to me:
But I'm not sure I have a better suggestion off the top of my head :// There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, unfortunately the |
||||||
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. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Tiny nit -- this paragraph starts off using the imperative mood There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But the previous sentence is in the indicative, so I think this is fine? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, it's not really a big deal either way :) |
||||||
|
||||||
``get_overloads`` can be used for introspecting an overloaded function at | ||||||
runtime. | ||||||
JelleZijlstra marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
.. 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 | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Add :func:`typing.get_overloads` and :func:`typing.clear_overloads`. | ||
Patch by Jelle Zijlstra. |
Uh oh!
There was an error while loading. Please reload this page.