|
1 | 1 | use crate::common::lock::LazyLock; |
2 | 2 | use crate::{ |
3 | 3 | AsObject, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, atomic_func, |
4 | | - builtins::{PyBaseExceptionRef, PyStrRef, PyTuple, PyTupleRef, PyType, PyTypeRef}, |
| 4 | + builtins::{PyBaseExceptionRef, PyStr, PyStrRef, PyTuple, PyTupleRef, PyType, PyTypeRef}, |
5 | 5 | class::{PyClassImpl, StaticType}, |
6 | 6 | function::{Either, FuncArgs, PyComparisonValue, PyMethodDef, PyMethodFlags}, |
7 | 7 | iter::PyExactSizeIterator, |
@@ -225,7 +225,21 @@ pub trait PyStructSequence: StaticType + PyClassImpl + Sized + 'static { |
225 | 225 | } else { |
226 | 226 | (String::new(), "...") |
227 | 227 | }; |
228 | | - let repr_str = format!("{}({}{})", Self::TP_NAME, body, suffix); |
| 228 | + // Build qualified name: if MODULE_NAME is already in TP_NAME, use it directly. |
| 229 | + // Otherwise, check __module__ attribute (set by #[pymodule] at runtime). |
| 230 | + let type_name = if Self::MODULE_NAME.is_some() { |
| 231 | + alloc::borrow::Cow::Borrowed(Self::TP_NAME) |
| 232 | + } else { |
| 233 | + let typ = zelf.class(); |
| 234 | + match typ.get_attr(identifier!(vm.ctx, __module__)) { |
| 235 | + Some(module) if module.downcastable::<PyStr>() => { |
| 236 | + let module_str = module.downcast_ref::<PyStr>().unwrap(); |
| 237 | + alloc::borrow::Cow::Owned(format!("{}.{}", module_str.as_str(), Self::NAME)) |
| 238 | + } |
| 239 | + _ => alloc::borrow::Cow::Borrowed(Self::TP_NAME), |
| 240 | + } |
| 241 | + }; |
| 242 | + let repr_str = format!("{}({}{})", type_name, body, suffix); |
229 | 243 | Ok(vm.ctx.new_str(repr_str)) |
230 | 244 | } |
231 | 245 |
|
|
0 commit comments