mirror of
https://github.com/python/cpython.git
synced 2025-10-08 16:11:51 +00:00
code_repr(): use %U to format the filename
Avoid useless unicode decoding/recoding of the filename.
This commit is contained in:
parent
f650e46646
commit
e3c7381c39
1 changed files with 12 additions and 8 deletions
|
@ -340,16 +340,20 @@ code_dealloc(PyCodeObject *co)
|
||||||
static PyObject *
|
static PyObject *
|
||||||
code_repr(PyCodeObject *co)
|
code_repr(PyCodeObject *co)
|
||||||
{
|
{
|
||||||
int lineno = -1;
|
int lineno;
|
||||||
char *filename = "???";
|
|
||||||
|
|
||||||
if (co->co_firstlineno != 0)
|
if (co->co_firstlineno != 0)
|
||||||
lineno = co->co_firstlineno;
|
lineno = co->co_firstlineno;
|
||||||
if (co->co_filename && PyUnicode_Check(co->co_filename))
|
else
|
||||||
filename = _PyUnicode_AsString(co->co_filename);
|
lineno = -1;
|
||||||
return PyUnicode_FromFormat(
|
if (co->co_filename && PyUnicode_Check(co->co_filename)) {
|
||||||
"<code object %.100U at %p, file \"%.300s\", line %d>",
|
return PyUnicode_FromFormat(
|
||||||
co->co_name, co, filename, lineno);
|
"<code object %.100U at %p, file \"%.300U\", line %d>",
|
||||||
|
co->co_name, co, co->co_filename, lineno);
|
||||||
|
} else {
|
||||||
|
return PyUnicode_FromFormat(
|
||||||
|
"<code object %.100U at %p, file ???, line %d>",
|
||||||
|
co->co_name, co, lineno);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue