mirror of
https://github.com/pybind/pybind11.git
synced 2026-05-23 22:34:48 +00:00
Force the builtin module key to be the correct type. (#2814)
* Force the builtin module key to be the correct type. Previously it was always going to be a std::string which converted into unicode. Python 2 appears to want module keys to be normal str types, so this was breaking code that expected plain string types in the builtins.keys() data structure * Add a simple unit test to ensure all built-in keys are str * Update the unit test so it will also run on pypy * Run pre-commit. Co-authored-by: Jesse Clemens <jesse.clemens@sony.com>
This commit is contained in:
@@ -266,7 +266,7 @@ PYBIND11_NOINLINE inline internals &get_internals() {
|
||||
const PyGILState_STATE state;
|
||||
} gil;
|
||||
|
||||
constexpr auto *id = PYBIND11_INTERNALS_ID;
|
||||
PYBIND11_STR_TYPE id(PYBIND11_INTERNALS_ID);
|
||||
auto builtins = handle(PyEval_GetBuiltins());
|
||||
if (builtins.contains(id) && isinstance<capsule>(builtins[id])) {
|
||||
internals_pp = static_cast<internals **>(capsule(builtins[id]));
|
||||
|
||||
Reference in New Issue
Block a user