Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork245
Display the correct signature for a decorated function in Python 3#765
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
sebastinas merged 3 commits intobpython:masterfrombfrascher:bugfix/decorated-function-signatureApr 2, 2019
Merged
Display the correct signature for a decorated function in Python 3#765
sebastinas merged 3 commits intobpython:masterfrombfrascher:bugfix/decorated-function-signatureApr 2, 2019
Uh oh!
There was an error while loading.Please reload this page.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
This patch changes it so that `inspect.signature` is used instead of`inspect.getfullargspec` to get a function's signature, when using Python 3.Python 3.3 introduced the `inspect.signature` function as a new way to get thesignature of a function (as an alternative to `inspect.getargspec` and`inspect.getfullargspec`). `inspect.signature` has the advantage that itpreserves the signature of a decorated function if `functools.wraps` is used todecorated the wrapper function. Having a function's signature available is veryhepful, especially when testing things out in a REPL.
Instead of referencing parameter kinds as class attributes on the private`_ParameterKind` class we reference them on the public `Parameter` class. Thishas two advantages:1) We don't use a private interface.2) The class attributes on `_ParameterKind` have only been added in Python 3.5, but on `Parameter` they have existed since Python 3.3.
Some built-in functions (e.g. `map`) can't be inspected with`inspect.getargspec`, `inspect.getfullargspec` or `inspect.signature`. Theexceptions from `inspect.getargspec` and `inspect.getfullargspec` are all caughtin the code, but `inspect.signature` raises a `ValueError` instead of a`TypeError`. This exception is now also caught.
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This patch changes it so that
inspect.signature
is used instead ofinspect.getfullargspec
to get a function's signature, when using Python 3.Python 3.3 introduced the
inspect.signature
function as a new way to get thesignature of a function (as an alternative to
inspect.getargspec
andinspect.getfullargspec
).inspect.signature
has the advantage that itpreserves the signature of a decorated function if
functools.wraps
is used todecorated the wrapper function. Having a function's signature available is very
hepful, especially when testing things out in a REPL.
The below images show the change in action (first the old behavior, then the new one):
I was only able to test the changes on Python 3.7.2, but since all used functionality is available since Python 3.3 (and I only touch code paths used on Python 3) I don't think anything should break on other versions.