Skip to content

Commit e66d264

Browse files
committed
Correct type return type
1 parent 75981e3 commit e66d264

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

Lib/test/test_symtable.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,6 @@ def test_id(self):
236236
self.assertGreater(self.generic_spam.get_id(), 0)
237237
self.assertGreater(self.GenericMine.get_id(), 0)
238238

239-
# TODO: RUSTPYTHON
240-
@unittest.expectedFailure
241239
def test_optimized(self):
242240
self.assertFalse(self.top.is_optimized())
243241

@@ -505,8 +503,6 @@ def test_bytes(self):
505503
top = symtable.symtable(code, "?", "exec")
506504
self.assertIsNotNone(find_block(top, "\u017d"))
507505

508-
# TODO: RUSTPYTHON
509-
@unittest.expectedFailure
510506
def test_symtable_repr(self):
511507
self.assertEqual(str(self.top), "<SymbolTable for module ?>")
512508
self.assertEqual(str(self.spam), "<Function SymbolTable for spam in ?>")
@@ -558,8 +554,6 @@ def test_file(self):
558554
self.assertIn(" local symbol 'spam': def_local", lines)
559555
self.assertIn(" symbol table for function 'spam':", lines)
560556

561-
# TODO: RUSTPYTHON
562-
@unittest.expectedFailure
563557
def test_stdin(self):
564558
with support.captured_stdin() as stdin:
565559
stdin.write(TEST_CODE)

vm/src/stdlib/symtable.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ mod symtable {
77
builtins::{PyDictRef, PyStrRef},
88
compiler,
99
};
10-
use rustpython_codegen::symboltable::{Symbol, SymbolFlags, SymbolScope, SymbolTable};
10+
use rustpython_codegen::symboltable::{
11+
CompilerScope, Symbol, SymbolFlags, SymbolScope, SymbolTable,
12+
};
1113
use std::fmt;
1214

1315
// Consts as defined at
@@ -101,7 +103,10 @@ mod symtable {
101103
pub const TYPE_TYPE_ALIAS: i32 = 5;
102104

103105
#[pyattr]
104-
pub const TYPE_TYPE_PARAM: i32 = 6;
106+
pub const TYPE_TYPE_PARAMETERS: i32 = 6;
107+
108+
#[pyattr]
109+
pub const TYPE_TYPE_VARIABLE: i32 = 7;
105110

106111
#[pyfunction]
107112
fn symtable(
@@ -147,8 +152,14 @@ mod symtable {
147152
}
148153

149154
#[pygetset(name = "type")]
150-
fn typ(&self) -> String {
151-
self.symtable.typ.to_string()
155+
fn typ(&self) -> i32 {
156+
match self.symtable.typ {
157+
CompilerScope::Function => TYPE_FUNCTION,
158+
CompilerScope::Class => TYPE_CLASS,
159+
CompilerScope::Module => TYPE_MODULE,
160+
CompilerScope::TypeParams => TYPE_TYPE_PARAMETERS,
161+
_ => -1, // TODO: missing types from the C implementation
162+
}
152163
}
153164

154165
#[pygetset]

0 commit comments

Comments
 (0)