add extra `name` method return `BorrowedValue<str>`
@@ -2,7 +2,11 @@ use super::{
mappingproxy::PyMappingProxy, object, PyClassMethod, PyDictRef, PyInt, PyList, PyStaticMethod,
PyStr, PyStrRef, PyTuple, PyTupleRef, PyWeak,
};
-use crate::common::{ascii, lock::PyRwLock};
+use crate::common::{
+ ascii,
+ borrow::BorrowedValue,
+ lock::{PyRwLock, PyRwLockReadGuard},
+};
use crate::{
function::{FuncArgs, KwArgs, OptionalArg},
protocol::{PyIterReturn, PyMappingMethods},
@@ -400,9 +404,16 @@ impl PyType {
vm.ctx.not_implemented()
}
- #[pyproperty(magic)]
- pub fn name(&self) -> String {
- self.slot_name().rsplit('.').next().unwrap().to_string()
+ #[pyproperty(name = "__name__")]
+ fn __name__(&self) -> String {
+ self.name().to_string()
+ }
+
+ pub fn name(&self) -> BorrowedValue<str> {
+ PyRwLockReadGuard::map(self.slots.name.read(), |slot_name| {
+ slot_name.as_ref().unwrap().rsplit('.').next().unwrap()
+ })
+ .into()
}
#[pymethod(magic)]
