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
cdcafb78
Kaydet (Commit)
cdcafb78
authored
Agu 24, 2014
tarafından
Antoine Pitrou
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #16808: inspect.stack() now returns a named tuple instead of a tuple.
Patch by Daniel Shahaf.
üst
1fa36268
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
25 additions
and
4 deletions
+25
-4
inspect.rst
Doc/library/inspect.rst
+8
-2
inspect.py
Lib/inspect.py
+6
-2
test_inspect.py
Lib/test/test_inspect.py
+8
-0
NEWS
Misc/NEWS
+3
-0
No files found.
Doc/library/inspect.rst
Dosyayı görüntüle @
cdcafb78
...
@@ -881,11 +881,17 @@ Classes and functions
...
@@ -881,11 +881,17 @@ Classes and functions
The interpreter stack
The interpreter stack
---------------------
---------------------
When the following functions return "frame records," each record is a tuple of
When the following functions return "frame records," each record is a
six items: the frame object, the filename, the line number of the current line,
:term:`named tuple`
``FrameInfo(frame, filename, lineno, function, code_context, index)``.
The tuple contains the frame object, the filename, the line number of the
current line,
the function name, a list of lines of context from the source code, and the
the function name, a list of lines of context from the source code, and the
index of the current line within that list.
index of the current line within that list.
.. versionchanged:: 3.5
Return a named tuple instead of a tuple.
.. note::
.. note::
Keeping references to frame objects, as found in the first element of the frame
Keeping references to frame objects, as found in the first element of the frame
...
...
Lib/inspect.py
Dosyayı görüntüle @
cdcafb78
...
@@ -1312,6 +1312,8 @@ def getlineno(frame):
...
@@ -1312,6 +1312,8 @@ def getlineno(frame):
# FrameType.f_lineno is now a descriptor that grovels co_lnotab
# FrameType.f_lineno is now a descriptor that grovels co_lnotab
return
frame
.
f_lineno
return
frame
.
f_lineno
FrameInfo
=
namedtuple
(
'FrameInfo'
,
(
'frame'
,)
+
Traceback
.
_fields
)
def
getouterframes
(
frame
,
context
=
1
):
def
getouterframes
(
frame
,
context
=
1
):
"""Get a list of records for a frame and all higher (calling) frames.
"""Get a list of records for a frame and all higher (calling) frames.
...
@@ -1319,7 +1321,8 @@ def getouterframes(frame, context=1):
...
@@ -1319,7 +1321,8 @@ def getouterframes(frame, context=1):
name, a list of lines of context, and index within the context."""
name, a list of lines of context, and index within the context."""
framelist
=
[]
framelist
=
[]
while
frame
:
while
frame
:
framelist
.
append
((
frame
,)
+
getframeinfo
(
frame
,
context
))
frameinfo
=
(
frame
,)
+
getframeinfo
(
frame
,
context
)
framelist
.
append
(
FrameInfo
(
*
frameinfo
))
frame
=
frame
.
f_back
frame
=
frame
.
f_back
return
framelist
return
framelist
...
@@ -1330,7 +1333,8 @@ def getinnerframes(tb, context=1):
...
@@ -1330,7 +1333,8 @@ def getinnerframes(tb, context=1):
name, a list of lines of context, and index within the context."""
name, a list of lines of context, and index within the context."""
framelist
=
[]
framelist
=
[]
while
tb
:
while
tb
:
framelist
.
append
((
tb
.
tb_frame
,)
+
getframeinfo
(
tb
,
context
))
frameinfo
=
(
tb
.
tb_frame
,)
+
getframeinfo
(
tb
,
context
)
framelist
.
append
(
FrameInfo
(
*
frameinfo
))
tb
=
tb
.
tb_next
tb
=
tb
.
tb_next
return
framelist
return
framelist
...
...
Lib/test/test_inspect.py
Dosyayı görüntüle @
cdcafb78
...
@@ -182,6 +182,14 @@ class TestInterpreterStack(IsTestBase):
...
@@ -182,6 +182,14 @@ class TestInterpreterStack(IsTestBase):
(
modfile
,
43
,
'argue'
,
[
' spam(a, b, c)
\n
'
],
0
))
(
modfile
,
43
,
'argue'
,
[
' spam(a, b, c)
\n
'
],
0
))
self
.
assertEqual
(
revise
(
*
mod
.
st
[
3
][
1
:]),
self
.
assertEqual
(
revise
(
*
mod
.
st
[
3
][
1
:]),
(
modfile
,
39
,
'abuse'
,
[
' self.argue(a, b, c)
\n
'
],
0
))
(
modfile
,
39
,
'abuse'
,
[
' self.argue(a, b, c)
\n
'
],
0
))
# Test named tuple fields
record
=
mod
.
st
[
0
]
self
.
assertIs
(
record
.
frame
,
mod
.
fr
)
self
.
assertEqual
(
record
.
lineno
,
16
)
self
.
assertEqual
(
record
.
filename
,
mod
.
__file__
)
self
.
assertEqual
(
record
.
function
,
'eggs'
)
self
.
assertIn
(
'inspect.stack()'
,
record
.
code_context
[
0
])
self
.
assertEqual
(
record
.
index
,
0
)
def
test_trace
(
self
):
def
test_trace
(
self
):
self
.
assertEqual
(
len
(
git
.
tr
),
3
)
self
.
assertEqual
(
len
(
git
.
tr
),
3
)
...
...
Misc/NEWS
Dosyayı görüntüle @
cdcafb78
...
@@ -124,6 +124,9 @@ Core and Builtins
...
@@ -124,6 +124,9 @@ Core and Builtins
Library
Library
-------
-------
-
Issue
#
16808
:
inspect
.
stack
()
now
returns
a
named
tuple
instead
of
a
tuple
.
Patch
by
Daniel
Shahaf
.
-
Issue
#
22236
:
Fixed
Tkinter
images
copying
operations
in
NoDefaultRoot
mode
.
-
Issue
#
22236
:
Fixed
Tkinter
images
copying
operations
in
NoDefaultRoot
mode
.
-
Issue
#
2527
:
Add
a
*
globals
*
argument
to
timeit
functions
,
in
order
to
-
Issue
#
2527
:
Add
a
*
globals
*
argument
to
timeit
functions
,
in
order
to
...
...
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