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
fcef60f5
Kaydet (Commit)
fcef60f5
authored
Nis 02, 2019
tarafından
Jeroen Demeyer
Kaydeden (comit)
Petr Viktorin
Nis 02, 2019
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
bpo-33261: guard access to __code__ attribute in inspect (GH-6448)
üst
487b73ab
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
9 deletions
+29
-9
inspect.py
Lib/inspect.py
+14
-9
inspect_fodder.py
Lib/test/inspect_fodder.py
+11
-0
test_inspect.py
Lib/test/test_inspect.py
+1
-0
2018-04-11-11-41-52.bpo-33291.-xLGf8.rst
...S.d/next/Library/2018-04-11-11-41-52.bpo-33291.-xLGf8.rst
+3
-0
No files found.
Lib/inspect.py
Dosyayı görüntüle @
fcef60f5
...
@@ -168,23 +168,30 @@ def isfunction(object):
...
@@ -168,23 +168,30 @@ def isfunction(object):
__kwdefaults__ dict of keyword only parameters with defaults"""
__kwdefaults__ dict of keyword only parameters with defaults"""
return
isinstance
(
object
,
types
.
FunctionType
)
return
isinstance
(
object
,
types
.
FunctionType
)
def
_has_code_flag
(
f
,
flag
):
"""Return true if ``f`` is a function (or a method or functools.partial
wrapper wrapping a function) whose code object has the given ``flag``
set in its flags."""
while
ismethod
(
f
):
f
=
f
.
__func__
f
=
functools
.
_unwrap_partial
(
f
)
if
not
isfunction
(
f
):
return
False
return
bool
(
f
.
__code__
.
co_flags
&
flag
)
def
isgeneratorfunction
(
obj
):
def
isgeneratorfunction
(
obj
):
"""Return true if the object is a user-defined generator function.
"""Return true if the object is a user-defined generator function.
Generator function objects provide the same attributes as functions.
Generator function objects provide the same attributes as functions.
See help(isfunction) for a list of attributes."""
See help(isfunction) for a list of attributes."""
obj
=
functools
.
_unwrap_partial
(
obj
)
return
_has_code_flag
(
obj
,
CO_GENERATOR
)
return
bool
((
isfunction
(
obj
)
or
ismethod
(
obj
))
and
obj
.
__code__
.
co_flags
&
CO_GENERATOR
)
def
iscoroutinefunction
(
obj
):
def
iscoroutinefunction
(
obj
):
"""Return true if the object is a coroutine function.
"""Return true if the object is a coroutine function.
Coroutine functions are defined with "async def" syntax.
Coroutine functions are defined with "async def" syntax.
"""
"""
obj
=
functools
.
_unwrap_partial
(
obj
)
return
_has_code_flag
(
obj
,
CO_COROUTINE
)
return
bool
(((
isfunction
(
obj
)
or
ismethod
(
obj
))
and
obj
.
__code__
.
co_flags
&
CO_COROUTINE
))
def
isasyncgenfunction
(
obj
):
def
isasyncgenfunction
(
obj
):
"""Return true if the object is an asynchronous generator function.
"""Return true if the object is an asynchronous generator function.
...
@@ -192,9 +199,7 @@ def isasyncgenfunction(obj):
...
@@ -192,9 +199,7 @@ def isasyncgenfunction(obj):
Asynchronous generator functions are defined with "async def"
Asynchronous generator functions are defined with "async def"
syntax and have "yield" expressions in their body.
syntax and have "yield" expressions in their body.
"""
"""
obj
=
functools
.
_unwrap_partial
(
obj
)
return
_has_code_flag
(
obj
,
CO_ASYNC_GENERATOR
)
return
bool
((
isfunction
(
obj
)
or
ismethod
(
obj
))
and
obj
.
__code__
.
co_flags
&
CO_ASYNC_GENERATOR
)
def
isasyncgen
(
object
):
def
isasyncgen
(
object
):
"""Return true if the object is an asynchronous generator."""
"""Return true if the object is an asynchronous generator."""
...
...
Lib/test/inspect_fodder.py
Dosyayı görüntüle @
fcef60f5
...
@@ -80,3 +80,14 @@ try:
...
@@ -80,3 +80,14 @@ try:
raise
Exception
()
raise
Exception
()
except
:
except
:
tb
=
sys
.
exc_info
()[
2
]
tb
=
sys
.
exc_info
()[
2
]
class
Callable
:
def
__call__
(
self
,
*
args
):
return
args
def
as_method_of
(
self
,
obj
):
from
types
import
MethodType
return
MethodType
(
self
,
obj
)
custom_method
=
Callable
()
.
as_method_of
(
42
)
del
Callable
Lib/test/test_inspect.py
Dosyayı görüntüle @
fcef60f5
...
@@ -146,6 +146,7 @@ class TestPredicates(IsTestBase):
...
@@ -146,6 +146,7 @@ class TestPredicates(IsTestBase):
self
.
istest
(
inspect
.
isfunction
,
'mod.spam'
)
self
.
istest
(
inspect
.
isfunction
,
'mod.spam'
)
self
.
istest
(
inspect
.
isfunction
,
'mod.StupidGit.abuse'
)
self
.
istest
(
inspect
.
isfunction
,
'mod.StupidGit.abuse'
)
self
.
istest
(
inspect
.
ismethod
,
'git.argue'
)
self
.
istest
(
inspect
.
ismethod
,
'git.argue'
)
self
.
istest
(
inspect
.
ismethod
,
'mod.custom_method'
)
self
.
istest
(
inspect
.
ismodule
,
'mod'
)
self
.
istest
(
inspect
.
ismodule
,
'mod'
)
self
.
istest
(
inspect
.
isdatadescriptor
,
'collections.defaultdict.default_factory'
)
self
.
istest
(
inspect
.
isdatadescriptor
,
'collections.defaultdict.default_factory'
)
self
.
istest
(
inspect
.
isgenerator
,
'(x for x in range(2))'
)
self
.
istest
(
inspect
.
isgenerator
,
'(x for x in range(2))'
)
...
...
Misc/NEWS.d/next/Library/2018-04-11-11-41-52.bpo-33291.-xLGf8.rst
0 → 100644
Dosyayı görüntüle @
fcef60f5
Do not raise AttributeError when calling the inspect functions
isgeneratorfunction, iscoroutinefunction, isasyncgenfunction on a method
created from an arbitrary callable. Instead, return False.
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