8000 bpo-20047: Make bytearray methods partition() and rpartition() rejecting by serhiy-storchaka · Pull Request #4158 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-20047: Make bytearray methods partition() and rpartition() rejecting #4158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 28, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fix the documentation.
  • Loading branch information
serhiy-storchaka committed Oct 28, 2017
commit 3f2ab7ad810ba8ad3e1d031d07c492c54b590d2f
10 changes: 6 additions & 4 deletions Doc/library/stdtypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2573,8 +2573,9 @@ arbitrary binary data.
bytearray.partition(sep)

Split the sequence at the first occurrence of *sep*, and return a 3-tuple
containing the part before the separator, the separator, and the part
after the separator. If the separator is not found, return a 3-tuple
containing the part before the separator, the separator itself or its
bytearray copy, and the part after the separator.
If the separator is not found, return a 3-tuple
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change is to add 'itself or its bytearray copy'. The asymmetry surprised me, but it matches current behavior.

>>> b'123456789'.partition(bytearray(b'45'))
(b'123', bytearray(b'45'), b'6789')
>>> bytearray(b'123456789').partition(b'45')
(bytearray(b'123'), bytearray(b'45'), bytearray(b'6789'))

The text and test changes look good.

containing a copy of the original sequence, followed by two empty bytes or
bytearray objects.

Expand Down Expand Up @@ -2629,8 +2630,9 @@ arbitrary binary data.
bytearray.rpartition(sep)

Split the sequence at the last occurrence of *sep*, and return a 3-tuple
containing the part before the separator, the separator, and the part
after the separator. If the separator is not found, return a 3-tuple
containing the part before the separator, the separator itself or its
bytearray copy, and the part after the separator.
If the separator is not found, return a 3-tuple
containing a copy of the original sequence, followed by two empty bytes or
bytearray objects.

Expand Down
19 changes: 10 additions & 9 deletions Objects/bytearrayobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1408,15 +1408,15 @@ Partition the bytearray into three parts using the given separator.

This will search for the separator sep in the bytearray. If the separator is
found, returns a 3-tuple containing the part before the separator, the
separator itself, and the part after it.
separator itself, and the part after it as new bytearray objects.

If the separator is not found, returns a 3-tuple containing the original
bytearray object and two empty bytearray objects.
If the separator is not found, returns a 3-tuple containing the copy of the
original bytearray object and two empty bytearray objects.
[clinic start generated code]*/

static PyObject *
bytearray_partition(PyByteArrayObject *self, PyObject *sep)
/*[clinic end generated code: output=45d2525ddd35f957 input=86f89223892b70b5]*/
/*[clinic end generated code: output=45d2525ddd35f957 input=8f644749ee4fc83a]*/
{
PyObject *bytesep, *result;

Expand All @@ -1441,19 +1441,20 @@ bytearray.rpartition
sep: object
/

Partition the bytes into three parts using the given separator.
Partition the bytearray into three parts using the given separator.

This will search for the separator sep in the bytearray, starting and the end.
This will search for the separator sep in the bytearray, starting at the end.
If the separator is found, returns a 3-tuple containing the part before the
separator, the separator itself, and the part after it.
separator, the separator itself, and the part after it as new bytearray
objects.

If the separator is not found, returns a 3-tuple containing two empty bytearray
objects and the original bytearray object.
objects and the copy of the original bytearray object.
[clinic start generated code]*/

static PyObject *
bytearray_rpartition(PyByteArrayObject *self, PyObject *sep)
/*[clinic end generated code: output=440de3c9426115e8 input=5f4094f2de87c8f3]*/
/*[clinic end generated code: output=440de3c9426115e8 input=7e3df3e6cb8fa0ac]*/
{
PyObject *bytesep, *result;

Expand Down
4 changes: 2 additions & 2 deletions Objects/bytesobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1834,7 +1834,7 @@ bytes.rpartition

Partition the bytes into three parts using the given separator.

This will search for the separator sep in the bytes, starting and the end. If
This will search for the separator sep in the bytes, starting at the end. If
the separator is found, returns a 3-tuple containing the part before the
separator, the separator itself, and the part after it.

Expand All @@ -1844,7 +1844,7 @@ objects and the original bytes object.

static PyObject *
bytes_rpartition_impl(PyBytesObject *self, Py_buffer *sep)
/*[clinic end generated code: output=191b114cbb028e50 input=67f689e63a62d478]*/
/*[clinic end generated code: output=191b114cbb028e50 input=d78db010c8cfdbe1]*/
{
return stringlib_rpartition(
(PyObject*) self,
Expand Down
17 changes: 9 additions & 8 deletions Objects/clinic/bytearrayobject.c.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,10 @@ PyDoc_STRVAR(bytearray_partition__doc__,
"\n"
"This will search for the separator sep in the bytearray. If the separator is\n"
"found, returns a 3-tuple containing the part before the separator, the\n"
"separator itself, and the part after it.\n"
"separator itself, and the part after it as new bytearray objects.\n"
"\n"
"If the separator is not found, returns a 3-tuple containing the original\n"
"bytearray object and two empty bytearray objects.");
"If the separator is not found, returns a 3-tuple containing the copy of the\n"
"original bytearray object and two empty bytearray objects.");

#define BYTEARRAY_PARTITION_METHODDEF \
{"partition", (PyCFunction)bytearray_partition, METH_O, bytearray_partition__doc__},
Expand All @@ -226,14 +226,15 @@ PyDoc_STRVAR(bytearray_rpartition__doc__,
"rpartition($self, sep, /)\n"
"--\n"
"\n"
"Partition the bytes into three parts using the given separator.\n"
"Partition the bytearray into three parts using the given separator.\n"
"\n"
"This will search for the separator sep in the bytearray, starting and the end.\n"
"This will search for the separator sep in the bytearray, starting at the end.\n"
"If the separator is found, returns a 3-tuple containing the part before the\n"
"separator, the separator itself, and the part after it.\n"
"separator, the separator itself, and the part after it as new bytearray\n"
"objects.\n"
"\n"
"If the separator is not found, returns a 3-tuple containing two empty bytearray\n"
"objects and the original bytearray object.");
"objects and the copy of the original bytearray object.");

#define BYTEARRAY_RPARTITION_METHODDEF \
{"rpartition", (PyCFunction)bytearray_rpartition, METH_O, bytearray_rpartition__doc__},
Expand Down Expand Up @@ -711,4 +712,4 @@ bytearray_sizeof(PyByteArrayObject *self, PyObject *Py_UNUSED(ignored))
{
return bytearray_sizeof_impl(self);
}
/*[clinic end generated code: output=e53f10084457a46b input=a9049054013a1b77]*/
/*[clinic end generated code: output=c2804d009182328c input=a9049054013a1b77]*/
4 changes: 2 additions & 2 deletions Objects/clinic/bytesobject.c.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ PyDoc_STRVAR(bytes_rpartition__doc__,
"\n"
"Partition the bytes into three parts using the given separator.\n"
"\n"
"This will search for the separator sep in the bytes, starting and the end. If\n"
"This will search for the separator sep in the bytes, starting at the end. If\n"
"the separator is found, returns a 3-tuple containing the part before the\n"
"separator, the separator itself, and the part after it.\n"
"\n"
Expand Down Expand Up @@ -499,4 +499,4 @@ bytes_fromhex(PyTypeObject *type, PyObject *arg)
exit:
return return_value;
}
/*[clinic end generated code: output=9e3374bd7d04c163 input=a9049054013a1b77]*/
/*[clinic end generated code: output=fc9e02359cc56d36 input=a9049054013a1b77]*/
4 changes: 2 additions & 2 deletions Objects/clinic/unicodeobject.c.h
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ PyDoc_STRVAR(unicode_rpartition__doc__,
"\n"
"Partition the string into three parts using the given separator.\n"
"\n"
"This will search for the separator in the string, starting and the end. If\n"
"This will search for the separator in the string, starting at the end. If\n"
"the separator is found, returns a 3-tuple containing the part before the\n"
"separator, the separator itself, and the part after it.\n"
"\n"
Expand Down Expand Up @@ -930,4 +930,4 @@ unicode_sizeof(PyObject *self, PyObject *Py_UNUSED(ignored))
{
return unicode_sizeof_impl(self);
}
/*[clinic end generated code: output=8fd799fd7f2cc724 input=a9049054013a1b77]*/
/*[clinic end generated code: output=816292e81a8a732e input=a9049054013a1b77]*/
4 changes: 2 additions & 2 deletions Objects/unicodeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -13067,7 +13067,7 @@ str.rpartition as unicode_rpartition = str.partition

Partition the string into three parts using the given separator.

This will search for the separator in the string, starting and the end. If
This will search for the separator in the string, starting at the end. If
the separator is found, returns a 3-tuple containing the part before the
separator, the separator itself, and the part after it.

Expand All @@ -13077,7 +13077,7 @@ and the original string.

static PyObject *
unicode_rpartition(PyObject *self, PyObject *sep)
/*[clinic end generated code: output=1aa13cf1156572aa input=e77c7acb69bdfca6]*/
/*[clinic end generated code: output=1aa13cf1156572aa input=c4b7db3ef5cf336a]*/
{
return PyUnicode_RPartition(self, sep);
}
Expand Down
0