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
e4543ab4
Commit
e4543ab4
authored
Feb 21, 2014
by
Yury Selivanov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
inspect.signature: Check for function-like objects before builtins. Issue #17159
parent
fed29e06
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
4 deletions
+20
-4
Lib/inspect.py
Lib/inspect.py
+4
-4
Lib/test/test_inspect.py
Lib/test/test_inspect.py
+16
-0
No files found.
Lib/inspect.py
View file @
e4543ab4
...
...
@@ -1911,15 +1911,15 @@ def _signature_internal(obj, follow_wrapper_chains=True, skip_bound_arg=True):
return
sig
.
replace
(
parameters
=
new_params
)
if
_signature_is_builtin
(
obj
):
return
_signature_from_builtin
(
Signature
,
obj
,
skip_bound_arg
=
skip_bound_arg
)
if
isfunction
(
obj
)
or
_signature_is_functionlike
(
obj
):
# If it's a pure Python function, or an object that is duck type
# of a Python function (Cython functions, for instance), then:
return
Signature
.
from_function
(
obj
)
if
_signature_is_builtin
(
obj
):
return
_signature_from_builtin
(
Signature
,
obj
,
skip_bound_arg
=
skip_bound_arg
)
if
isinstance
(
obj
,
functools
.
partial
):
wrapped_sig
=
_signature_internal
(
obj
.
func
,
follow_wrapper_chains
,
...
...
Lib/test/test_inspect.py
View file @
e4543ab4
...
...
@@ -14,6 +14,7 @@ import sys
import
types
import
unicodedata
import
unittest
import
unittest.mock
try
:
from
concurrent.futures
import
ThreadPoolExecutor
...
...
@@ -1836,6 +1837,21 @@ class TestSignatureObject(unittest.TestCase):
(
'kwargs'
,
...,
...,
"var_keyword"
)),
...))
# Test with cython-like builtins:
_orig_isdesc
=
inspect
.
ismethoddescriptor
def
_isdesc
(
obj
):
if
hasattr
(
obj
,
'_builtinmock'
):
return
True
return
_orig_isdesc
(
obj
)
with
unittest
.
mock
.
patch
(
'inspect.ismethoddescriptor'
,
_isdesc
):
builtin_func
=
funclike
(
func
)
# Make sure that our mock setup is working
self
.
assertFalse
(
inspect
.
ismethoddescriptor
(
builtin_func
))
builtin_func
.
_builtinmock
=
True
self
.
assertTrue
(
inspect
.
ismethoddescriptor
(
builtin_func
))
self
.
assertEqual
(
inspect
.
signature
(
builtin_func
),
sig_func
)
def
test_signature_functionlike_class
(
self
):
# We only want to duck type function-like objects,
# not classes.
...
...
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