Skip to content

Commit f1c1470

Browse files
committed
type.__new__: preserve caller namespace when reading __qualname__
1 parent 1a9b10e commit f1c1470

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

Lib/test/test_descr.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4987,7 +4987,6 @@ class Inside:
49874987
self.assertEqual(Y.__qualname__, 'Y')
49884988
self.assertEqual(Y.Inside.__qualname__, 'Y.Inside')
49894989

4990-
@unittest.expectedFailure # TODO: RUSTPYTHON
49914990
def test_qualname_dict(self):
49924991
ns = {'__qualname__': 'some.name'}
49934992
tp = type('Foo', (), ns)

crates/vm/src/builtins/type.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1867,15 +1867,15 @@ impl Constructor for PyType {
18671867
(metatype, base.to_owned(), bases, base_is_type)
18681868
};
18691869

1870-
let qualname = dict
1871-
.pop_item(identifier!(vm, __qualname__).as_object(), vm)?
1870+
let mut attributes = dict.to_attributes(vm);
1871+
let qualname = attributes
1872+
.shift_remove(identifier!(vm, __qualname__))
18721873
.map(|obj| downcast_qualname(obj, vm))
18731874
.transpose()?
18741875
.unwrap_or_else(|| {
18751876
// If __qualname__ is not provided, we can use the name as default
18761877
name.clone().into_wtf8()
18771878
});
1878-
let mut attributes = dict.to_attributes(vm);
18791879

18801880
// Check __doc__ for surrogates - raises UnicodeEncodeError during type creation
18811881
if let Some(doc) = attributes.get(identifier!(vm, __doc__))

0 commit comments

Comments
 (0)