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
d919556f
Commit
d919556f
authored
9 years ago
by
Yury Selivanov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue 24298: Fix signature() to properly unwrap wrappers around bound methods
parent
e69cebae
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
0 deletions
+24
-0
Lib/inspect.py
Lib/inspect.py
+8
-0
Lib/test/test_inspect.py
Lib/test/test_inspect.py
+13
-0
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/inspect.py
View file @
d919556f
...
...
@@ -1911,6 +1911,14 @@ def _signature_internal(obj, follow_wrapper_chains=True, skip_bound_arg=True):
# Was this function wrapped by a decorator?
if
follow_wrapper_chains
:
obj
=
unwrap
(
obj
,
stop
=
(
lambda
f
:
hasattr
(
f
,
"__signature__"
)))
if
isinstance
(
obj
,
types
.
MethodType
):
# If the unwrapped object is a *method*, we might want to
# skip its first parameter (self).
# See test_signature_wrapped_bound_method for details.
return
_signature_internal
(
obj
,
follow_wrapper_chains
=
follow_wrapper_chains
,
skip_bound_arg
=
skip_bound_arg
)
try
:
sig
=
obj
.
__signature__
...
...
This diff is collapsed.
Click to expand it.
Lib/test/test_inspect.py
View file @
d919556f
...
...
@@ -1939,6 +1939,19 @@ class TestSignatureObject(unittest.TestCase):
with
self
.
assertRaisesRegex
(
ValueError
,
'invalid method signature'
):
self
.
signature
(
Test
())
def
test_signature_wrapped_bound_method
(
self
):
# Issue 24298
class
Test
:
def
m1
(
self
,
arg1
,
arg2
=
1
)
->
int
:
pass
@
functools
.
wraps
(
Test
().
m1
)
def
m1d
(
*
args
,
**
kwargs
):
pass
self
.
assertEqual
(
self
.
signature
(
m1d
),
(((
'arg1'
,
...,
...,
"positional_or_keyword"
),
(
'arg2'
,
1
,
...,
"positional_or_keyword"
)),
int
))
def
test_signature_on_classmethod
(
self
):
class
Test
:
@
classmethod
...
...
This diff is collapsed.
Click to expand it.
Misc/NEWS
View file @
d919556f
...
...
@@ -274,6 +274,9 @@ Library
- Issue #23898: Fix inspect.classify_class_attrs() to support attributes
with overloaded __eq__ and __bool__. Patch by Mike Bayer.
- Issue #24298: Fix inspect.signature() to correctly unwrap wrappers
around bound methods.
IDLE
----
...
...
This diff is collapsed.
Click to expand it.
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