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
14709144
Unverified
Kaydet (Commit)
14709144
authored
Ara 31, 2017
tarafından
Antoine Pitrou
Kaydeden (comit)
GitHub
Ara 31, 2017
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
bpo-32468: Better frame repr() (#5067)
bpo-32468: Better frame repr()
üst
0a37a300
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
1 deletion
+52
-1
test_frame.py
Lib/test/test_frame.py
+41
-0
2017-12-31-20-32-58.bpo-32468.YBs__0.rst
...S.d/next/Library/2017-12-31-20-32-58.bpo-32468.YBs__0.rst
+1
-0
frameobject.c
Objects/frameobject.c
+10
-1
No files found.
Lib/test/test_frame.py
Dosyayı görüntüle @
14709144
import
re
import
types
import
types
import
unittest
import
unittest
import
weakref
import
weakref
...
@@ -159,5 +160,45 @@ class FrameLocalsTest(unittest.TestCase):
...
@@ -159,5 +160,45 @@ class FrameLocalsTest(unittest.TestCase):
self
.
assertEqual
(
inner
.
f_locals
,
{})
self
.
assertEqual
(
inner
.
f_locals
,
{})
class
ReprTest
(
unittest
.
TestCase
):
"""
Tests for repr(frame).
"""
def
test_repr
(
self
):
def
outer
():
x
=
5
y
=
6
def
inner
():
z
=
x
+
2
1
/
0
t
=
9
return
inner
()
offset
=
outer
.
__code__
.
co_firstlineno
try
:
outer
()
except
ZeroDivisionError
as
e
:
tb
=
e
.
__traceback__
frames
=
[]
while
tb
:
frames
.
append
(
tb
.
tb_frame
)
tb
=
tb
.
tb_next
else
:
self
.
fail
(
"should have raised"
)
f_this
,
f_outer
,
f_inner
=
frames
file_repr
=
re
.
escape
(
repr
(
__file__
))
self
.
assertRegex
(
repr
(
f_this
),
r"^<frame at 0x[0-9a-fA-F]+, file
%
s, line
%
d, code test_repr>$"
%
(
file_repr
,
offset
+
23
))
self
.
assertRegex
(
repr
(
f_outer
),
r"^<frame at 0x[0-9a-fA-F]+, file
%
s, line
%
d, code outer>$"
%
(
file_repr
,
offset
+
7
))
self
.
assertRegex
(
repr
(
f_inner
),
r"^<frame at 0x[0-9a-fA-F]+, file
%
s, line
%
d, code inner>$"
%
(
file_repr
,
offset
+
5
))
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
unittest
.
main
()
unittest
.
main
()
Misc/NEWS.d/next/Library/2017-12-31-20-32-58.bpo-32468.YBs__0.rst
0 → 100644
Dosyayı görüntüle @
14709144
Improve frame repr() to mention filename, code name and current line number.
Objects/frameobject.c
Dosyayı görüntüle @
14709144
...
@@ -547,6 +547,15 @@ frame_sizeof(PyFrameObject *f)
...
@@ -547,6 +547,15 @@ frame_sizeof(PyFrameObject *f)
PyDoc_STRVAR
(
sizeof__doc__
,
PyDoc_STRVAR
(
sizeof__doc__
,
"F.__sizeof__() -> size of F in memory, in bytes"
);
"F.__sizeof__() -> size of F in memory, in bytes"
);
static
PyObject
*
frame_repr
(
PyFrameObject
*
f
)
{
int
lineno
=
PyFrame_GetLineNumber
(
f
);
return
PyUnicode_FromFormat
(
"<frame at %p, file %R, line %d, code %S>"
,
f
,
f
->
f_code
->
co_filename
,
lineno
,
f
->
f_code
->
co_name
);
}
static
PyMethodDef
frame_methods
[]
=
{
static
PyMethodDef
frame_methods
[]
=
{
{
"clear"
,
(
PyCFunction
)
frame_clear
,
METH_NOARGS
,
{
"clear"
,
(
PyCFunction
)
frame_clear
,
METH_NOARGS
,
clear__doc__
},
clear__doc__
},
...
@@ -565,7 +574,7 @@ PyTypeObject PyFrame_Type = {
...
@@ -565,7 +574,7 @@ PyTypeObject PyFrame_Type = {
0
,
/* tp_getattr */
0
,
/* tp_getattr */
0
,
/* tp_setattr */
0
,
/* tp_setattr */
0
,
/* tp_reserved */
0
,
/* tp_reserved */
0
,
/* tp_repr */
(
reprfunc
)
frame_repr
,
/* tp_repr */
0
,
/* tp_as_number */
0
,
/* tp_as_number */
0
,
/* tp_as_sequence */
0
,
/* tp_as_sequence */
0
,
/* tp_as_mapping */
0
,
/* tp_as_mapping */
...
...
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