Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
378d7064
Commit
378d7064
authored
May 18, 2017
by
Dong-hee Na
Committed by
Yury Selivanov
May 17, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-30149: Fix partialmethod without explicit self parameter (#1308)
parent
f8d05b3a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
4 deletions
+48
-4
Lib/inspect.py
Lib/inspect.py
+9
-4
Lib/test/test_inspect.py
Lib/test/test_inspect.py
+35
-0
Misc/NEWS
Misc/NEWS
+4
-0
No files found.
Lib/inspect.py
View file @
378d7064
...
...
@@ -2241,11 +2241,16 @@ def _signature_from_callable(obj, *,
sigcls
=
sigcls
)
sig
=
_signature_get_partial
(
wrapped_sig
,
partialmethod
,
(
None
,))
first_wrapped_param
=
tuple
(
wrapped_sig
.
parameters
.
values
())[
0
]
new_params
=
(
first_wrapped_param
,)
+
tuple
(
sig
.
parameters
.
values
())
return
sig
.
replace
(
parameters
=
new_params
)
if
first_wrapped_param
.
kind
is
Parameter
.
VAR_POSITIONAL
:
# First argument of the wrapped callable is `*args`, as in
# `partialmethod(lambda *args)`.
return
sig
else
:
sig_params
=
tuple
(
sig
.
parameters
.
values
())
assert
first_wrapped_param
is
not
sig_params
[
0
]
new_params
=
(
first_wrapped_param
,)
+
sig_params
return
sig
.
replace
(
parameters
=
new_params
)
if
isfunction
(
obj
)
or
_signature_is_functionlike
(
obj
):
# If it's a pure Python function, or an object that is duck type
...
...
Lib/test/test_inspect.py
View file @
378d7064
...
...
@@ -1986,6 +1986,41 @@ class TestSignatureObject(unittest.TestCase):
(
'kwargs'
,
...,
int
,
"var_keyword"
)),
...))
def
test_signature_without_self
(
self
):
def
test_args_only
(
*
args
):
# NOQA
pass
def
test_args_kwargs_only
(
*
args
,
**
kwargs
):
# NOQA
pass
class
A
:
@
classmethod
def
test_classmethod
(
*
args
):
# NOQA
pass
@
staticmethod
def
test_staticmethod
(
*
args
):
# NOQA
pass
f1
=
functools
.
partialmethod
((
test_classmethod
),
1
)
f2
=
functools
.
partialmethod
((
test_args_only
),
1
)
f3
=
functools
.
partialmethod
((
test_staticmethod
),
1
)
f4
=
functools
.
partialmethod
((
test_args_kwargs_only
),
1
)
self
.
assertEqual
(
self
.
signature
(
test_args_only
),
(((
'args'
,
...,
...,
'var_positional'
),),
...))
self
.
assertEqual
(
self
.
signature
(
test_args_kwargs_only
),
(((
'args'
,
...,
...,
'var_positional'
),
(
'kwargs'
,
...,
...,
'var_keyword'
)),
...))
self
.
assertEqual
(
self
.
signature
(
A
.
f1
),
(((
'args'
,
...,
...,
'var_positional'
),),
...))
self
.
assertEqual
(
self
.
signature
(
A
.
f2
),
(((
'args'
,
...,
...,
'var_positional'
),),
...))
self
.
assertEqual
(
self
.
signature
(
A
.
f3
),
(((
'args'
,
...,
...,
'var_positional'
),),
...))
self
.
assertEqual
(
self
.
signature
(
A
.
f4
),
(((
'args'
,
...,
...,
'var_positional'
),
(
'kwargs'
,
...,
...,
'var_keyword'
)),
...))
@
cpython_only
@
unittest
.
skipIf
(
MISSING_C_DOCSTRINGS
,
"Signature information for builtins requires docstrings"
)
...
...
Misc/NEWS
View file @
378d7064
...
...
@@ -323,6 +323,10 @@ Extension Modules
Library
-------
- bpo-30149: inspect.signature() now supports callables with
variable-argument parameters wrapped with partialmethod.
Patch by Dong-hee Na.
- bpo-30301: Fix AttributeError when using SimpleQueue.empty() under
*spawn* and *forkserver* start methods.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment