mirror of
https://github.com/python/cpython.git
synced 2025-09-10 02:36:56 +00:00
inspect: Fix getfullargspec to support builtin module-level functions. Issue #20711
This commit is contained in:
parent
b226026299
commit
8c185ee12e
2 changed files with 16 additions and 2 deletions
|
@ -1827,9 +1827,16 @@ def _signature_fromstr(cls, obj, s, skip_bound_arg=True):
|
||||||
p(f.args.kwarg, empty)
|
p(f.args.kwarg, empty)
|
||||||
|
|
||||||
if self_parameter is not None:
|
if self_parameter is not None:
|
||||||
|
# Possibly strip the bound argument:
|
||||||
|
# - We *always* strip first bound argument if
|
||||||
|
# it is a module.
|
||||||
|
# - We don't strip first bound argument if
|
||||||
|
# skip_bound_arg is False.
|
||||||
assert parameters
|
assert parameters
|
||||||
if getattr(obj, '__self__', None) and skip_bound_arg:
|
_self = getattr(obj, '__self__', None)
|
||||||
# strip off self, it's already been bound
|
self_isbound = _self is not None
|
||||||
|
self_ismodule = ismodule(_self)
|
||||||
|
if self_isbound and (self_ismodule or skip_bound_arg):
|
||||||
parameters.pop(0)
|
parameters.pop(0)
|
||||||
else:
|
else:
|
||||||
# for builtins, self parameter is always positional-only!
|
# for builtins, self parameter is always positional-only!
|
||||||
|
|
|
@ -643,6 +643,13 @@ class TestClassesAndFunctions(unittest.TestCase):
|
||||||
self.assertFullArgSpecEquals(_pickle.Pickler(io.BytesIO()).dump,
|
self.assertFullArgSpecEquals(_pickle.Pickler(io.BytesIO()).dump,
|
||||||
args_e=['self', 'obj'], formatted='(self, obj)')
|
args_e=['self', 'obj'], formatted='(self, obj)')
|
||||||
|
|
||||||
|
self.assertFullArgSpecEquals(
|
||||||
|
os.stat,
|
||||||
|
args_e=['path'],
|
||||||
|
kwonlyargs_e=['dir_fd', 'follow_symlinks'],
|
||||||
|
kwonlydefaults_e={'dir_fd': None, 'follow_symlinks': True},
|
||||||
|
formatted='(path, *, dir_fd=None, follow_symlinks=True)')
|
||||||
|
|
||||||
@cpython_only
|
@cpython_only
|
||||||
@unittest.skipIf(MISSING_C_DOCSTRINGS,
|
@unittest.skipIf(MISSING_C_DOCSTRINGS,
|
||||||
"Signature information for builtins requires docstrings")
|
"Signature information for builtins requires docstrings")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue