diff --git a/Lib/test/test_symtable.py b/Lib/test/test_symtable.py index 59f418484..ae93ee8d9 100644 --- a/Lib/test/test_symtable.py +++ b/Lib/test/test_symtable.py @@ -543,7 +543,6 @@ class SymtableTest(unittest.TestCase): self.assertEqual(repr(class_A.lookup('x')), "") - @unittest.expectedFailure # TODO: RUSTPYTHON def test_symtable_entry_repr(self): expected = f"" self.assertEqual(repr(self.top._table), expected) diff --git a/crates/vm/src/stdlib/symtable.rs b/crates/vm/src/stdlib/symtable.rs index 881c55198..570a48a8e 100644 --- a/crates/vm/src/stdlib/symtable.rs +++ b/crates/vm/src/stdlib/symtable.rs @@ -3,9 +3,10 @@ pub(crate) use _symtable::module_def; #[pymodule] mod _symtable { use crate::{ - PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, + Py, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, builtins::{PyDictRef, PyStrRef}, compiler, + types::Representable, }; use alloc::fmt; use rustpython_codegen::symboltable::{ @@ -132,7 +133,7 @@ mod _symtable { } #[pyattr] - #[pyclass(name = "SymbolTable")] + #[pyclass(name = "symtable entry")] #[derive(PyPayload)] struct PySymbolTable { symtable: SymbolTable, @@ -144,7 +145,7 @@ mod _symtable { } } - #[pyclass] + #[pyclass(with(Representable))] impl PySymbolTable { #[pygetset] fn name(&self) -> String { @@ -210,6 +211,19 @@ mod _symtable { } } + impl Representable for PySymbolTable { + #[inline] + fn repr_str(zelf: &Py, vm: &VirtualMachine) -> PyResult { + Ok(format!( + "<{} {}({}), line {}>", + Self::class(&vm.ctx).name(), + zelf.symtable.name, + zelf.id(), + zelf.symtable.line_number + )) + } + } + #[pyattr] #[pyclass(name = "Symbol")] #[derive(PyPayload)]