Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged
JelleZijlstra merged 14 commits intopython:mainfrommikeziminio:fix-issue-114894
Feb 10, 2024

Conversation

mikeziminio
Copy link
Contributor

@mikeziminiomikeziminio commentedFeb 2, 2024
edited by bedevere-appbot
Loading

@@ -868,6 +868,20 @@ array_slice(arrayobject *a, Py_ssize_t ilow, Py_ssize_t ihigh)
return (PyObject *)np;
}

/*[clinic input]
Copy link
Member

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)

Copy link
ContributorAuthor

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)

Thanks for the comment. I'll try to do it now.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

done

@mikeziminio
Copy link
ContributorAuthor

@JelleZijlstra Jelle, I've added tests and documentation)

@JelleZijlstraJelleZijlstra self-requested a reviewFebruary 2, 2024 19:28
Copy link
Member

@JelleZijlstraJelleZijlstra left a 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)?

a = array.array(self.typecode, self.example)
self.assertRaises(TypeError, a.clear, 42)
a.clear()
self.assertEqual(a, array.array(self.typecode))
Copy link
Member

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?

Copy link
ContributorAuthor

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]))

Copy link
Member

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()

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

done

@aisk
Copy link
Member

aisk commentedFeb 3, 2024
edited
Loading

In my personal view, according to the original issue, the intention behind adding theclear method is to allowarray.array to implementcollections.abc.MutableSequence, so we can add a test to test it and ensure we don't break it in the future.

There is already a relevant test case in

deftest_MutableSequence(self):
, so what we need to do is simply includearray.array in this existing test case.

sobolevn and mikeziminio reacted with thumbs up emoji

mikeziminioand others added4 commitsFebruary 6, 2024 09:32
Co-authored-by: AN Long <aisk@users.noreply.github.com>
…F-dSd.rstCo-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
@mikeziminio
Copy link
ContributorAuthor

In my personal view, according to the original issue, the intention behind adding theclear method is to allowarray.array to implementcollections.abc.MutableSequence, so we can add a test to test it and ensure we don't break it in the future.

There is already a relevant test case in

deftest_MutableSequence(self):

, so what we need to do is simply includearray.array in this existing test case.

done

I added only theissubclass check (withoutisinstance), because forisinstance it would have to be check all typecodes.

@@ -9,6 +9,7 @@
from random import choice, randrange
from itertools import product, chain, combinations
import string
import array
Copy link
Member

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.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

done

@rhettingerrhettinger removed their request for reviewFebruary 6, 2024 16:16
mikeziminioand others added2 commitsFebruary 7, 2024 07:19
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
@mikeziminio
Copy link
ContributorAuthor

@JelleZijlstra@aisk Guys, if I understand correctly, I made all the changes according to the reviews.
Please tell me what further steps are needed to merge the PR.

@aisk
Copy link
Member

aisk commentedFeb 8, 2024

LGTM, I think the next step is to wait for a core member to approve and merge it.

mikeziminio reacted with thumbs up emoji

@Jason-Y-Z
Copy link
Contributor

Thanks all for the efforts, sorry for tagging but gentle nudge to@vstinner who seems to have touched the relevant files recently (according toBLAME).

@Jason-Y-Z
Copy link
Contributor

Thanks!

fsc-eriker pushed a commit to fsc-eriker/cpython that referenced this pull requestFeb 14, 2024
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>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@aiskaiskaisk left review comments

@JelleZijlstraJelleZijlstraJelleZijlstra approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@mikeziminio@aisk@Jason-Y-Z@JelleZijlstra

[8]ページ先頭

©2009-2025 Movatter.jp