mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
Return the orginal string only if it's a real str or unicode
instance, otherwise make a copy.
This commit is contained in:
parent
8a5e6790d9
commit
0fe940c862
2 changed files with 18 additions and 4 deletions
|
@ -2401,8 +2401,15 @@ string_zfill(PyStringObject *self, PyObject *args)
|
|||
return NULL;
|
||||
|
||||
if (PyString_GET_SIZE(self) >= width) {
|
||||
Py_INCREF(self);
|
||||
return (PyObject*) self;
|
||||
if (PyString_CheckExact(self)) {
|
||||
Py_INCREF(self);
|
||||
return (PyObject*) self;
|
||||
}
|
||||
else
|
||||
return PyString_FromStringAndSize(
|
||||
PyString_AS_STRING(self),
|
||||
PyString_GET_SIZE(self)
|
||||
);
|
||||
}
|
||||
|
||||
fill = width - PyString_GET_SIZE(self);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue