type.__new__: preserve caller namespace when reading __qualname__ (#7524)

* type.__new__: preserve caller namespace when reading __qualname__

* type.__new__: preserve caller namespace when reading __qualname__
This commit is contained in:
Huy Vũ (Josh) authored and GitHub committed 2026-03-29 00:51:49 +09:00
1 parent 88cbcc9f95
commit f5eb35ce59
2 files changed
+3 -2

No files matched your search

-1
View File
@@ -4987,7 +4987,6 @@ class ClassPropertiesAndMethods(unittest.TestCase):
self.assertEqual(Y.__qualname__, 'Y')
self.assertEqual(Y.Inside.__qualname__, 'Y.Inside')
@unittest.expectedFailure # TODO: RUSTPYTHON
def test_qualname_dict(self):
ns = {'__qualname__': 'some.name'}
tp = type('Foo', (), ns)
+3 -1
View File
@@ -1868,14 +1868,16 @@ impl Constructor for PyType {
};
let qualname = dict
.pop_item(identifier!(vm, __qualname__).as_object(), vm)?
.get_item_opt(identifier!(vm, __qualname__), vm)?
.map(|obj| downcast_qualname(obj, vm))
.transpose()?
.unwrap_or_else(|| {
// If __qualname__ is not provided, we can use the name as default
name.clone().into_wtf8()
});
let mut attributes = dict.to_attributes(vm);
attributes.shift_remove(identifier!(vm, __qualname__));
// Check __doc__ for surrogates - raises UnicodeEncodeError during type creation
if let Some(doc) = attributes.get(identifier!(vm, __doc__))