-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
CLN: change getargspec -> signature #12325
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 1 commit
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 |
---|---|---|
|
@@ -71,7 +71,30 @@ def bytes_to_str(b, encoding=None): | |
return b.decode(encoding or 'utf-8') | ||
|
||
def signature(f): | ||
return list(inspect.signature(f).parameters.keys()) | ||
from collections import namedtuple | ||
sig = inspect.signature(f) | ||
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. where did you get all this from? is it already defined somewhere we can just import it? 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. I've borrowed it from django/django#4846 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. can you add a refernce to that django issue here (and comment that we copied directly) |
||
args = [ | ||
p.name for p in sig.parameters.values() | ||
if p.kind == inspect.Parameter.POSITIONAL_OR_KEYWORD | ||
] | ||
varargs = [ | ||
p.name for p in sig.parameters.values() | ||
if p.kind == inspect.Parameter.VAR_POSITIONAL | ||
] | ||
varargs = varargs[0] if varargs else None | ||
keywords = [ | ||
p.name for p in sig.parameters.values() | ||
if p.kind == inspect.Parameter.VAR_KEYWORD | ||
] | ||
keywords = keywords[0] if keywords else None | ||
defaults = [ | ||
p.default for p in sig.parameters.values() | ||
if p.kind == inspect.Parameter.POSITIONAL_OR_KEYWORD | ||
and p.default is not p.empty | ||
] or None | ||
argspec = namedtuple('Signature',['args','defaults', | ||
'varargs','keywords']) | ||
return argspec(args,defaults,varargs,keywords) | ||
|
||
# have to explicitly put builtins into the namespace | ||
range = range | ||
|
@@ -110,7 +133,7 @@ def bytes_to_str(b, encoding='ascii'): | |
return b | ||
|
||
def signature(f): | ||
return inspect.getargspec(f).args | ||
return inspect.getargspec(f) | ||
|
||
# import iterator versions of these functions | ||
range = xrange | ||
|
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.
put the import at the top of the file