Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.4k
gh-114894: add array.array.clear() method#114919
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
@@ -868,6 +868,20 @@ array_slice(arrayobject *a, Py_ssize_t ilow, Py_ssize_t ihigh) | |||
return (PyObject *)np; | |||
} | |||
/*[clinic input] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
This will also need new unit tests (probably intest_array.py
but I haven't checked) and a documentation entry (inarray.rst
)
There was a problem hiding this comment.
Choose a reason for 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 (inarray.rst
)
Thanks for the comment. I'll try to do it now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
done
3368a6b
to9c2c360
Compare@JelleZijlstra Jelle, I've added tests and documentation) |
There was a problem hiding this comment.
Choose a reason for 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
)?
Lib/test/test_array.py Outdated
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.
Choose a reason for 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 thatlen(a) == 0
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
All the testing logic from thetest_array.py
file works so that the methods are tested for all possibletypecode
.
To be honest, initially I used array comparison expecting that there would be atypecode
check, but then I looked atarray_richcompare()
and realized that comparing arrays using the==
operator is not suitable for checking the sametypecode
.
Therefore, I added two checks - thelen()
you suggested and thetypecode
comparison (just in case of future optimizations).
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.
Choose a reason for 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()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
done
Misc/NEWS.d/next/Library/2024-02-02-15-50-13.gh-issue-114894.DF-dSd.rst OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
aisk commentedFeb 3, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
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 in28bb296
array.array in this existing test case. |
Co-authored-by: AN Long <aisk@users.noreply.github.com>
…F-dSd.rstCo-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
done I added only the |
Lib/test/test_collections.py Outdated
@@ -9,6 +9,7 @@ | |||
from random import choice, randrange | |||
from itertools import product, chain, combinations | |||
import string | |||
import array |
There was a problem hiding this comment.
Choose a reason for 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
done
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
@JelleZijlstra@aisk Guys, if I understand correctly, I made all the changes according to the reviews. |
LGTM, I think the next step is to wait for a core member to approve and merge it. |
Thanks all for the efforts, sorry for tagging but gentle nudge to@vstinner who seems to have touched the relevant files recently (according to |
Thanks! |
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>Co-authored-by: AN Long <aisk@users.noreply.github.com>Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Uh oh!
There was an error while loading.Please reload this page.