Skip to content

Commit 84da0e2

Browse files
authored
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
1 parent 3de0402 commit 84da0e2

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

include/pybind11/cast.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -507,20 +507,19 @@ struct string_caster {
507507
static constexpr size_t UTF_N = 8 * sizeof(CharT);
508508

509509
bool load(handle src, bool) {
510-
handle load_src = src;
511510
if (!src) {
512511
return false;
513512
}
514-
if (!PyUnicode_Check(load_src.ptr())) {
515-
return load_raw(load_src);
513+
if (!PyUnicode_Check(src.ptr())) {
514+
return load_raw(src);
516515
}
517516

518517
// For UTF-8 we avoid the need for a temporary `bytes` object by using
519518
// `PyUnicode_AsUTF8AndSize`.
520519
if (UTF_N == 8) {
521520
Py_ssize_t size = -1;
522521
const auto *buffer
523-
= reinterpret_cast<const CharT *>(PyUnicode_AsUTF8AndSize(load_src.ptr(), &size));
522+
= reinterpret_cast<const CharT *>(PyUnicode_AsUTF8AndSize(src.ptr(), &size));
524523
if (!buffer) {
525524
PyErr_Clear();
526525
return false;
@@ -533,7 +532,7 @@ struct string_caster {
533532
}
534533

535534
auto utfNbytes
536-
= reinterpret_steal<object>(PyUnicode_AsEncodedString(load_src.ptr(),
535+
= reinterpret_steal<object>(PyUnicode_AsEncodedString(src.ptr(),
537536
UTF_N == 8 ? "utf-8"
538537
: UTF_N == 16 ? "utf-16"
539538
: "utf-32",

0 commit comments

Comments
 (0)