GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — gh-114894: add array.array.clear() method by mikeziminio · Pull Request #114919 · python/cpython Conversation
|
| return (PyObject *)np; | ||
| } | ||
|
|
||
| /*[clinic input] |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This 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.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This will also need new unit tests (probably in
test_array.pybut I haven't checked) and a documentation entry (inarray.rst)
Thanks for the comment. I'll try to do it now.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
done
Sorry, something went wrong.
There was an error while loading. Please reload this page.
3368a6b to
9c2c360
Compare
|
@JelleZijlstra Jelle, I've added tests and documentation) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Can you also add this to the What's New document for Python 3.13 (Doc/whatsnew/3.13.rst)?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| a = array.array(self.typecode, self.example) | ||
| self.assertRaises(TypeError, a.clear, 42) | ||
| a.clear() | ||
| self.assertEqual(a, array.array(self.typecode)) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This is a bit of an indirect test, why not instead test that len(a) == 0?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
All the testing logic from the test_array.py file works so that the methods are tested for all possible typecode.
To be honest, initially I used array comparison expecting that there would be a typecode check, but then I looked at array_richcompare() and realized that comparing arrays using the == operator is not suitable for checking the same typecode.
Therefore, I added two checks - the len() you suggested and the typecode comparison (just in case of future optimizations).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| a.append(self.example[2]) | ||
| a.append(self.example[3]) | ||
| self.assertEqual(a, array.array(self.typecode, self.example[2:4])) | ||
|
|
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Add 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.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
done
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
In my personal view, according to the original issue, the intention behind adding the There is already a relevant test case in cpython/Lib/test/test_collections.py Line 1968 in 28bb296
array.array in this existing test case.
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Co-authored-by: AN Long <[email protected]>
…F-dSd.rst Co-authored-by: Jelle Zijlstra <[email protected]>
done I added only the |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| from random import choice, randrange | ||
| from itertools import product, chain, combinations | ||
| import string | ||
| import array |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: These imports are basically sorted alphabetically, so this line may move to the first line.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
done
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Co-authored-by: Jelle Zijlstra <[email protected]>
Co-authored-by: Jelle Zijlstra <[email protected]>
|
@JelleZijlstra @aisk Guys, if I understand correctly, I made all the changes according to the reviews. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
LGTM, I think the next step is to wait for a core member to approve and merge it. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks all for the efforts, sorry for tagging but gentle nudge to @vstinner who seems to have touched the relevant files recently (according to |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: AN Long <[email protected]> Co-authored-by: Jelle Zijlstra <[email protected]>
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.