Skip to content

Commit

Permalink
Refactor PyString.to_str
Browse files Browse the repository at this point in the history
Co-authored-by: David Hewitt <mail@davidhewitt.dev>
  • Loading branch information
LilyFoote and davidhewitt committed Feb 21, 2024
1 parent 6d9ce3e commit ef65874
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions src/types/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,7 @@ impl PyString {

#[cfg(not(any(Py_3_10, not(Py_LIMITED_API))))]
{
let bytes = unsafe {
#[allow(deprecated)]
self.py()
.from_owned_ptr_or_err::<PyBytes>(ffi::PyUnicode_AsUTF8String(self.as_ptr()))
}?;
let bytes = self.as_borrowed().encode_utf8()?.into_gil_ref();
Ok(unsafe { std::str::from_utf8_unchecked(bytes.as_bytes()) })
}
}
Expand Down

0 comments on commit ef65874

Please sign in to comment.