refactor: remove needless load_src alias in string_caster (#6093)
`load_src` was a Python 2-era leftover. A removed branch used to reassign
it to a temporary unicode object; since that was deleted with Python 2
support, it is now an exact, never-reassigned alias of `src`. Use `src`
directly.
Spotted in review of #6092.
Assisted-by: ClaudeCode:claude-opus-4.8
diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h
index 32e730f..fb67ff8 100644
--- a/include/pybind11/cast.h
+++ b/include/pybind11/cast.h
@@ -507,12 +507,11 @@
static constexpr size_t UTF_N = 8 * sizeof(CharT);
bool load(handle src, bool) {
- handle load_src = src;
if (!src) {
return false;
}
- if (!PyUnicode_Check(load_src.ptr())) {
- return load_raw(load_src);
+ if (!PyUnicode_Check(src.ptr())) {
+ return load_raw(src);
}
// For UTF-8 we avoid the need for a temporary `bytes` object by using
@@ -520,7 +519,7 @@
if (UTF_N == 8) {
Py_ssize_t size = -1;
const auto *buffer
- = reinterpret_cast<const CharT *>(PyUnicode_AsUTF8AndSize(load_src.ptr(), &size));
+ = reinterpret_cast<const CharT *>(PyUnicode_AsUTF8AndSize(src.ptr(), &size));
if (!buffer) {
PyErr_Clear();
return false;
@@ -533,7 +532,7 @@
}
auto utfNbytes
- = reinterpret_steal<object>(PyUnicode_AsEncodedString(load_src.ptr(),
+ = reinterpret_steal<object>(PyUnicode_AsEncodedString(src.ptr(),
UTF_N == 8 ? "utf-8"
: UTF_N == 16 ? "utf-16"
: "utf-32",