From cd96f2c49f565544a650c5e6686e3b906b1c6364 Mon Sep 17 00:00:00 2001 From: ShaharNaveh <50263213+ShaharNaveh@users.noreply.github.com> Date: Mon, 15 Jun 2026 17:17:51 +0300 Subject: [PATCH] Fix builtin class names not being interned --- Lib/test/test_dataclasses/__init__.py | 1 - Lib/test/test_pydoc/test_pydoc.py | 1 - crates/vm/src/builtins/asyncgenerator.rs | 1 + crates/vm/src/function/method.rs | 8 ++++++++ crates/vm/src/function/mod.rs | 2 +- crates/vm/src/types/zoo.rs | 3 +++ 6 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_dataclasses/__init__.py b/Lib/test/test_dataclasses/__init__.py index 1b8c810a714..1a6dc850ab9 100644 --- a/Lib/test/test_dataclasses/__init__.py +++ b/Lib/test/test_dataclasses/__init__.py @@ -3977,7 +3977,6 @@ class WithCorrectSuper(CorrectSuper): # that we create internally. self.assertEqual(CorrectSuper.args, ["default", "default"]) - @unittest.skip("TODO: RUSTPYTHON; Crash - static type name must be already interned but async_generator_wrapped_value is not") def test_original_class_is_gced(self): # gh-135228: Make sure when we replace the class with slots=True, the original class # gets garbage collected. diff --git a/Lib/test/test_pydoc/test_pydoc.py b/Lib/test/test_pydoc/test_pydoc.py index 066b9b4dbe1..46f8ba60f8b 100644 --- a/Lib/test/test_pydoc/test_pydoc.py +++ b/Lib/test/test_pydoc/test_pydoc.py @@ -556,7 +556,6 @@ def test_stripid(self): self.assertEqual(stripid(""), "") - @unittest.skip("TODO: RUSTPYTHON; Panic") def test_builtin_with_more_than_four_children(self): """Tests help on builtin object which have more than four child classes. diff --git a/crates/vm/src/builtins/asyncgenerator.rs b/crates/vm/src/builtins/asyncgenerator.rs index 9edf38c43a9..dea40062a9a 100644 --- a/crates/vm/src/builtins/asyncgenerator.rs +++ b/crates/vm/src/builtins/asyncgenerator.rs @@ -818,4 +818,5 @@ pub(crate) fn init(ctx: &'static Context) { PyAsyncGenASend::extend_class(ctx, ctx.types.async_generator_asend); PyAsyncGenAThrow::extend_class(ctx, ctx.types.async_generator_athrow); PyAnextAwaitable::extend_class(ctx, ctx.types.anext_awaitable); + PyAsyncGenWrappedValue::extend_class(ctx, ctx.types.async_generator_wrapped_value); } diff --git a/crates/vm/src/function/method.rs b/crates/vm/src/function/method.rs index ee483e361e6..12eda50c9d5 100644 --- a/crates/vm/src/function/method.rs +++ b/crates/vm/src/function/method.rs @@ -5,6 +5,7 @@ use crate::{ builtin_func::{PyNativeFunction, PyNativeMethod}, descriptor::PyMethodDescriptor, }, + class::PyClassDef, function::{IntoPyNativeFn, PyNativeFn}, }; @@ -331,3 +332,10 @@ impl Py { #[pyclass] impl HeapMethodDef {} + +pub(crate) fn init(ctx: &'static Context) { + // TODO: Should we extend the class instead of interning only the name? + // HeapMethodDef::extend_class(ctx, ctx.types.method_def); + + let _ = ctx.intern_str(HeapMethodDef::NAME); +} diff --git a/crates/vm/src/function/mod.rs b/crates/vm/src/function/mod.rs index 4be94e3f0be..7eb87fea3ed 100644 --- a/crates/vm/src/function/mod.rs +++ b/crates/vm/src/function/mod.rs @@ -5,7 +5,7 @@ mod builtin; mod either; mod fspath; mod getset; -mod method; +pub(crate) mod method; mod number; mod protocol; mod time; diff --git a/crates/vm/src/types/zoo.rs b/crates/vm/src/types/zoo.rs index 0394f672cf8..13d439345f7 100644 --- a/crates/vm/src/types/zoo.rs +++ b/crates/vm/src/types/zoo.rs @@ -266,5 +266,8 @@ impl TypeZoo { template::init(context); descriptor::init(context); crate::stdlib::_typing::init(context); + + // RustPython specific + crate::function::method::init(context); } }