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 authored Feb 21, 2024
1 parent 6d9ce3e commit d17bfd8
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/types/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,8 @@ 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()) })
}?;
Ok(unsafe { std::str::from_utf8_unchecked(bytes.as_bytes()) })
}
Expand Down

0 comments on commit d17bfd8

Please sign in to comment.