test_builtin.py: test_type_qualname fix

This commit is contained in:
hydrogen602
2024-05-12 23:10:31 -05:00
committed by Jeong, YunWon
parent 07fdcb6160
commit 61feb43aba
2 changed files with 9 additions and 2 deletions

View File

@@ -2441,8 +2441,6 @@ class TestType(unittest.TestCase):
A.__name__ = b'A'
self.assertEqual(A.__name__, 'C')
# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_type_qualname(self):
A = type('A', (), {'__qualname__': 'B.C'})
self.assertEqual(A.__name__, 'A')

View File

@@ -206,6 +206,15 @@ impl PyType {
slots.flags |= PyTypeFlags::HAS_DICT
}
if let Some(qualname) = attrs.get(identifier!(ctx, __qualname__)) {
if !qualname.fast_isinstance(ctx.types.str_type) {
return Err(format!(
"type __qualname__ must be a str, not {}",
qualname.class().name()
));
}
}
let new_type = PyRef::new_ref(
PyType {
base: Some(base),