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

fix: improve str exceptions and consistency with python #3826

Merged

Conversation

Skylion007
Copy link
Collaborator

@Skylion007 Skylion007 commented Mar 25, 2022

Description

  • Use error_already_set() to provide more informative exceptions and better alignment with CPython exception strings
  • Replaces the related compatibility macro.
  • Raise CodecError instead of TypeError in the byte constructor to be consistent with the fix in Raise codec errors when casting to std::string #2903

Suggested changelog entry:

* Improve exception handling in python str bindings

@Skylion007 Skylion007 changed the title Improve str exceptions fix: improve str exceptions and consistency with cpython Mar 25, 2022
@Skylion007 Skylion007 closed this Mar 25, 2022
@Skylion007 Skylion007 reopened this Mar 25, 2022
@Skylion007 Skylion007 changed the title fix: improve str exceptions and consistency with cpython fix: improve str exceptions and consistency with python Mar 25, 2022
@jagerman
Copy link
Member

Revert macro change just in case

Why keep the macro?

@Skylion007
Copy link
Collaborator Author

Skylion007 commented Mar 25, 2022

Why keep the macro?

In case some third party caster uses it? I am fine with nuking them, but we should probably make a separate PR to nuke them all at once.

@henryiii
Copy link
Collaborator

I see at least a few users:

https://cs.github.com/?scopeName=All+repos&scope=&q=PYBIND11_BYTES_AS_STRING_AND_SIZE

Tencent/MMKV: POSIX/Python/libmmkv_python.cpp‎ for example.

@henryiii
Copy link
Collaborator

(There are quite a lot of users of our compatibility macros overall - if we want to get rid of them, we need deprecation messages, etc.)

@jagerman
Copy link
Member

Hurray for downstream users using undocumented internal macros! 😞

@Skylion007 Skylion007 closed this Mar 25, 2022
@Skylion007 Skylion007 reopened this Mar 25, 2022
Copy link
Collaborator

@rwgk rwgk left a comment

Choose a reason for hiding this comment

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

MUCH better, thanks for cleaning this up Aaron!

@Skylion007 Skylion007 merged commit 3a183d4 into pybind:master Mar 25, 2022
@Skylion007 Skylion007 deleted the skylion007/str-bytes-better-exceptions branch March 25, 2022 20:01
@github-actions github-actions bot added the needs changelog Possibly needs a changelog entry label Mar 25, 2022
@henryiii henryiii removed the needs changelog Possibly needs a changelog entry label Mar 29, 2022
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.

4 participants