Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
8dfb4576
Kaydet (Commit)
8dfb4576
authored
Şub 21, 2014
tarafından
Yury Selivanov
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
inspect.signature: Check for function-like objects before builtins. Issue #17159
üst
e2df3ea6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
4 deletions
+20
-4
inspect.py
Lib/inspect.py
+4
-4
test_inspect.py
Lib/test/test_inspect.py
+16
-0
No files found.
Lib/inspect.py
Dosyayı görüntüle @
8dfb4576
...
@@ -1911,15 +1911,15 @@ def _signature_internal(obj, follow_wrapper_chains=True, skip_bound_arg=True):
...
@@ -1911,15 +1911,15 @@ def _signature_internal(obj, follow_wrapper_chains=True, skip_bound_arg=True):
return
sig
.
replace
(
parameters
=
new_params
)
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
isfunction
(
obj
)
or
_signature_is_functionlike
(
obj
):
# If it's a pure Python function, or an object that is duck type
# If it's a pure Python function, or an object that is duck type
# of a Python function (Cython functions, for instance), then:
# of a Python function (Cython functions, for instance), then:
return
Signature
.
from_function
(
obj
)
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
):
if
isinstance
(
obj
,
functools
.
partial
):
wrapped_sig
=
_signature_internal
(
obj
.
func
,
wrapped_sig
=
_signature_internal
(
obj
.
func
,
follow_wrapper_chains
,
follow_wrapper_chains
,
...
...
Lib/test/test_inspect.py
Dosyayı görüntüle @
8dfb4576
...
@@ -14,6 +14,7 @@ import sys
...
@@ -14,6 +14,7 @@ import sys
import
types
import
types
import
unicodedata
import
unicodedata
import
unittest
import
unittest
import
unittest.mock
try
:
try
:
from
concurrent.futures
import
ThreadPoolExecutor
from
concurrent.futures
import
ThreadPoolExecutor
...
@@ -1836,6 +1837,21 @@ class TestSignatureObject(unittest.TestCase):
...
@@ -1836,6 +1837,21 @@ class TestSignatureObject(unittest.TestCase):
(
'kwargs'
,
...
,
...
,
"var_keyword"
)),
(
'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
):
def
test_signature_functionlike_class
(
self
):
# We only want to duck type function-like objects,
# We only want to duck type function-like objects,
# not classes.
# 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