Skip to content

feat: add a pybind function to clear a list. - #5153

Merged
rwgk merged 4 commits into
pybind:masterfrom
TCKnet:master
Jun 7, 2024
Merged

feat: add a pybind function to clear a list.#5153
rwgk merged 4 commits into
pybind:masterfrom
TCKnet:master

Conversation

@TCKnet

@TCKnetTCKnet commented Jun 3, 2024

Copy link
Copy Markdown
Contributor

Description

Add py::list::clear().

See also: https://stackoverflow.com/questions/23489177/how-to-clear-a-pylistobject

Suggested changelog entry:

``py::list`` gained a ``.clear()`` method.

@TCKnet

Copy link
Copy Markdown
ContributorAuthor

It seems that this is a system/test configuration/version issue rather than an issue with the CL per se. Could a maintainer have a look? Tthat would be awesome! Thank you very much in advance!

Using cmake version 3.29.4
Error: Could not find linux asset for cmake version 3.29.4
Using cmake version 3.29.4
Error: Could not find darwin asset for cmake version 3.29.4

@rwgk

rwgk commented Jun 6, 2024

Copy link
Copy Markdown
Collaborator

About to close/reopen this PR to trigger a fresh rerun of the GitHub Actions.

@rwgkrwgk closed this Jun 6, 2024
@rwgkrwgk reopened this Jun 6, 2024
rwgk
rwgk approved these changes Jun 6, 2024

@rwgkrwgk left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM. I think this is a useful small addition, especially because the implementation isn't exactly obvious (why is there no PyList_Clear()?).

Comment threadinclude/pybind11/pytypes.h Outdated
throw error_already_set();
}
}
void clear() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can you add the non-const comment the other pybind11 clear methods have?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Done. Thanks for catching this!

@Skylion007Skylion007 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Except for the comment issue, looks good.

@rwgk
rwgk merged commit 35ff42b into pybind:masterJun 7, 2024
@github-actionsgithub-actionsBot added the needs changelog Possibly needs a changelog entry label Jun 7, 2024
@henryiiihenryiii changed the title Add a pybind function to clear a list.feat: add a pybind function to clear a list.Jun 23, 2024
@henryiiihenryiii removed the needs changelog Possibly needs a changelog entry label Jun 26, 2024
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@TCKnet@rwgk@Skylion007@henryiii