From 4a00e11f37124c65302233632a9fb4603e6182a6 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Tue, 23 Jun 2026 21:52:18 -0400 Subject: [PATCH] refactor: remove needless load_src alias in string_caster `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 --- include/pybind11/cast.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index 32e730f50a..fb67ff8d56 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -507,12 +507,11 @@ struct string_caster { 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 @@ struct string_caster { if (UTF_N == 8) { Py_ssize_t size = -1; const auto *buffer - = reinterpret_cast(PyUnicode_AsUTF8AndSize(load_src.ptr(), &size)); + = reinterpret_cast(PyUnicode_AsUTF8AndSize(src.ptr(), &size)); if (!buffer) { PyErr_Clear(); return false; @@ -533,7 +532,7 @@ struct string_caster { } auto utfNbytes - = reinterpret_steal(PyUnicode_AsEncodedString(load_src.ptr(), + = reinterpret_steal(PyUnicode_AsEncodedString(src.ptr(), UTF_N == 8 ? "utf-8" : UTF_N == 16 ? "utf-16" : "utf-32",