Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Lib/test/test_symtable.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,6 @@ def test_symbol_repr(self):
self.assertEqual(repr(class_A.lookup('x')),
"<symbol 'x': LOCAL, DEF_LOCAL|DEF_FREE_CLASS>")

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_symtable_entry_repr(self):
expected = f"<symtable entry top({self.top.get_id()}), line {self.top.get_lineno()}>"
self.assertEqual(repr(self.top._table), expected)
Expand Down
20 changes: 17 additions & 3 deletions crates/vm/src/stdlib/symtable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -132,7 +133,7 @@ mod _symtable {
}

#[pyattr]
#[pyclass(name = "SymbolTable")]
#[pyclass(name = "symtable entry")]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SymbolTable itself is not an entry, is this correct?

#[derive(PyPayload)]
struct PySymbolTable {
symtable: SymbolTable,
Expand All @@ -144,7 +145,7 @@ mod _symtable {
}
}

#[pyclass]
#[pyclass(with(Representable))]
impl PySymbolTable {
#[pygetset]
fn name(&self) -> String {
Expand Down Expand Up @@ -210,6 +211,19 @@ mod _symtable {
}
}

impl Representable for PySymbolTable {
#[inline]
fn repr_str(zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<String> {
Ok(format!(
"<{} {}({}), line {}>",
Self::class(&vm.ctx).name(),
zelf.symtable.name,
zelf.id(),
zelf.symtable.line_number
))
}
}

#[pyattr]
#[pyclass(name = "Symbol")]
#[derive(PyPayload)]
Expand Down
Loading