Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add C++ binding to throw AttributeError #3387

Merged
merged 2 commits into from
Oct 23, 2021

Conversation

Skylion007
Copy link
Collaborator

Description

Closes #687 . Adds a C++ binding to throw and catch AttributeError, useful for defining custom __setattr__. The other exception I was eyeing adding was NameError, but it is rare for any user to want to manually throw them, unlike with an AttributeError. Then again, we already expose bindings for ImportError, so I would advocating for eventually adding NameError was well at some point.

This does not significantly extend the API surface considering it supports the exceptions of other types. This doesn't implement any exception translation from C++ errors so it should be a very backwards compatible and lightweight change.

Suggested changelog entry:

* Add C++ Exception type to throw and catch AttributeError. Useful for defining custom ``__setattr__`` and ``__getattr__`` methods.

@Skylion007 Skylion007 requested review from rwgk and henryiii October 20, 2021 16:27
@Skylion007 Skylion007 changed the title (feat): Add C++ binding to throw AttributeError feat: Add C++ binding to throw AttributeError Oct 20, 2021
Copy link
Collaborator

@henryiii henryiii left a comment

Choose a reason for hiding this comment

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

Mostly dragging my feet because I'm expecting a new patch release, and this is technically a new feature. But we've let in features this small before in patches (hasn't checked to see how small it was), and it should be quite safe. Fine with me.

@henryiii henryiii merged commit 78ee782 into pybind:master Oct 23, 2021
@github-actions github-actions bot added the needs changelog Possibly needs a changelog entry label Oct 23, 2021
@Skylion007 Skylion007 linked an issue Oct 25, 2021 that may be closed by this pull request
3 tasks
@henryiii henryiii removed the needs changelog Possibly needs a changelog entry label Dec 21, 2021
Sign up for free to 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.

Add attribute_error
3 participants