Skip to content

Commit 808b071

Browse files
authored
Fix builtin class names not being interned (RustPython#8116)
1 parent 3aa94d8 commit 808b071

6 files changed

Lines changed: 13 additions & 3 deletions

File tree

Lib/test/test_dataclasses/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3977,7 +3977,6 @@ class WithCorrectSuper(CorrectSuper):
39773977
# that we create internally.
39783978
self.assertEqual(CorrectSuper.args, ["default", "default"])
39793979

3980-
@unittest.skip("TODO: RUSTPYTHON; Crash - static type name must be already interned but async_generator_wrapped_value is not")
39813980
def test_original_class_is_gced(self):
39823981
# gh-135228: Make sure when we replace the class with slots=True, the original class
39833982
# gets garbage collected.

Lib/test/test_pydoc/test_pydoc.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,6 @@ def test_stripid(self):
556556
self.assertEqual(stripid("<type 'exceptions.Exception'>"),
557557
"<type 'exceptions.Exception'>")
558558

559-
@unittest.skip("TODO: RUSTPYTHON; Panic")
560559
def test_builtin_with_more_than_four_children(self):
561560
"""Tests help on builtin object which have more than four child classes.
562561

crates/vm/src/builtins/asyncgenerator.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,4 +818,5 @@ pub(crate) fn init(ctx: &'static Context) {
818818
PyAsyncGenASend::extend_class(ctx, ctx.types.async_generator_asend);
819819
PyAsyncGenAThrow::extend_class(ctx, ctx.types.async_generator_athrow);
820820
PyAnextAwaitable::extend_class(ctx, ctx.types.anext_awaitable);
821+
PyAsyncGenWrappedValue::extend_class(ctx, ctx.types.async_generator_wrapped_value);
821822
}

crates/vm/src/function/method.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::{
55
builtin_func::{PyNativeFunction, PyNativeMethod},
66
descriptor::PyMethodDescriptor,
77
},
8+
class::PyClassDef,
89
function::{IntoPyNativeFn, PyNativeFn},
910
};
1011

@@ -331,3 +332,10 @@ impl Py<HeapMethodDef> {
331332

332333
#[pyclass]
333334
impl HeapMethodDef {}
335+
336+
pub(crate) fn init(ctx: &'static Context) {
337+
// TODO: Should we extend the class instead of interning only the name?
338+
// HeapMethodDef::extend_class(ctx, ctx.types.method_def);
339+
340+
let _ = ctx.intern_str(HeapMethodDef::NAME);
341+
}

crates/vm/src/function/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ mod builtin;
55
mod either;
66
mod fspath;
77
mod getset;
8-
mod method;
8+
pub(crate) mod method;
99
mod number;
1010
mod protocol;
1111
mod time;

crates/vm/src/types/zoo.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,5 +266,8 @@ impl TypeZoo {
266266
template::init(context);
267267
descriptor::init(context);
268268
crate::stdlib::_typing::init(context);
269+
270+
// RustPython specific
271+
crate::function::method::init(context);
269272
}
270273
}

0 commit comments

Comments
 (0)