mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
add extra name method return BorrowedValue<str>
Signed-off-by: snowapril <sinjihng@gmail.com>
This commit is contained in:
@@ -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)]
|
||||
|
||||
Reference in New Issue
Block a user