-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
FIX/API: use inspect.signature for python3 #8795
Conversation
This allows functions with keyword-only arguments to have their signatures introspected. Also makes this bit of code 3.6 compatible. This slightly changes the API in python 3 as all of arguments are available for completion, not just the optional ones.
pass | ||
else: | ||
try: | ||
args, _, _1, defaults = inspect.getargspec(call_obj) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder what would happen if on py2, this could a) unwrap (signature does unwrap until a "signature" is found, getargspec does not) and b) check for a simple get_additional_completions(...)
function which we could then set in out decorator. getdoc()
already does something similar...
so:
addons = []
while true:
if hasattr(call_obj, "get_additional_completions"):
addons.extend(call_obj.get_additional_completitions())
break
if hasattr(call_obj, "__wrapped__"):
call_obj = call_obj.__wrapped__
else:
break
[...]
ret.extend(addons)
We ship a backport of |
Then mpl must ship that as well or needs a dependency on ipython... |
@JanSchulz I'm not sure I understand. This is a PR to IPython, so why would IPython using its own utility affect MPL? |
This PR is part of the "unpack labeled data for plotting": make it possible to use a call like this The problem is that to construct the signature object, mpl needs |
@JanSchulz Just moving that file over is probably a non-starter for now as mpl (still) supports py2.6 so we don't have |
26717c3
to
8a95d9a
Compare
Probably the best route on the mpl side is to try to import IPython and use it if available. I think this is ok because the only reason we want to tack the signatures on to legacy python is for nice introspection in IPython. |
But then your PR here should also try to use the internal ipython copy oft inspect (if python doesn't have it...) in all versions... edit: Ah, you already did it :-) |
no, mpl will only fall back to the IPython version in versions of python which don't already have |
@tacaswell the next release will be 4.1, so this will get in. We haven't started making breaking changes on IPython to push master to 5.x and start backporting, yet. |
FIX/API: use inspect.signature for python3
This allows functions with keyword-only arguments to have their signatures introspected.
Also makes this bit of code 3.6 compatible (@Carreau I see your 3.5 and raise you a 3.6 馃槣 )
Found this via working on matplotlib/matplotlib#4829 where for python 3.3+ we mark the
data
kwarg as keyword-only.This is a slight change in behavior as it makes all arguments, not just the optional ones. This can easily be changed back, but leaving it for now as I would propose that including all arguments is a better behavior.