| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| Expand Up | @@ -1014,6 +1014,29 @@ def test_pop(self): | |
| array.array(self.typecode, self.example[3:]+self.example[:-1]) | ||
| ) | ||
|
|
||
| def test_clear(self): | ||
| a = array.array(self.typecode, self.example) | ||
| with self.assertRaises(TypeError): | ||
| a.clear(42) | ||
| a.clear() | ||
| self.assertEqual(len(a), 0) | ||
| self.assertEqual(a.typecode, self.typecode) | ||
|
|
||
| a = array.array(self.typecode) | ||
| a.clear() | ||
| self.assertEqual(len(a), 0) | ||
| self.assertEqual(a.typecode, self.typecode) | ||
|
|
||
| a = array.array(self.typecode, self.example) | ||
| a.clear() | ||
| a.append(self.example[2]) | ||
| a.append(self.example[3]) | ||
| self.assertEqual(a, array.array(self.typecode, self.example[2:4])) | ||
|
|
||
|
Comment thread
Copy link
Copy Markdown
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityAdd a test that an array with exported buffers cannot be cleared, something like this (untested): with memoryview(a):
with self.assertRaises(BufferError):
a.clear()
Sorry, something went wrong.
All reactions
Copy link
Copy Markdown
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Qualitydone
Sorry, something went wrong.
All reactions
|
||
| with memoryview(a): | ||
| with self.assertRaises(BufferError): | ||
| a.clear() | ||
|
|
||
| def test_reverse(self): | ||
| a = array.array(self.typecode, self.example) | ||
| self.assertRaises(TypeError, a.reverse, 42) | ||
| Expand Down | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Add :meth:`array.array.clear`. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| Expand Up | @@ -868,6 +868,21 @@ array_slice(arrayobject *a, Py_ssize_t ilow, Py_ssize_t ihigh) | |
| return (PyObject *)np; | ||
| } | ||
|
|
||
| /*[clinic input] | ||
|
Comment thread
Copy link
Copy Markdown
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityThis will also need new unit tests (probably in test_array.py but I haven't checked) and a documentation entry (in array.rst)
Sorry, something went wrong.
All reactions
Copy link
Copy Markdown
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality
Thanks for the comment. I'll try to do it now.
Sorry, something went wrong.
All reactions
Copy link
Copy Markdown
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Qualitydone
Sorry, something went wrong.
All reactions
|
||
| array.array.clear | ||
|
|
||
| Remove all items from the array. | ||
| [clinic start generated code]*/ | ||
|
|
||
| static PyObject * | ||
| array_array_clear_impl(arrayobject *self) | ||
| /*[clinic end generated code: output=5efe0417062210a9 input=5dffa30e94e717a4]*/ | ||
| { | ||
| if (array_resize(self, 0) == -1) { | ||
| return NULL; | ||
| } | ||
| Py_RETURN_NONE; | ||
| } | ||
|
|
||
| /*[clinic input] | ||
| array.array.__copy__ | ||
| Expand Down Expand Up | @@ -2342,6 +2357,7 @@ static PyMethodDef array_methods[] = { | |
| ARRAY_ARRAY_APPEND_METHODDEF | ||
| ARRAY_ARRAY_BUFFER_INFO_METHODDEF | ||
| ARRAY_ARRAY_BYTESWAP_METHODDEF | ||
| ARRAY_ARRAY_CLEAR_METHODDEF | ||
| ARRAY_ARRAY___COPY___METHODDEF | ||
| ARRAY_ARRAY_COUNT_METHODDEF | ||
| ARRAY_ARRAY___DEEPCOPY___METHODDEF | ||
| Expand Down | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Back | FazBrowse Home | New Git URL |
Uh oh!
There was an error while loading. Please reload this page.