From bb77ab2afd3df078fca55fb8411bf02d71e9ea3f Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Fri, 27 Jun 2025 20:01:49 +0900 Subject: [PATCH 1/2] ParamSpec.__repr__ --- vm/src/stdlib/typing.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/vm/src/stdlib/typing.rs b/vm/src/stdlib/typing.rs index 25a26015a4..e9cd1cf270 100644 --- a/vm/src/stdlib/typing.rs +++ b/vm/src/stdlib/typing.rs @@ -343,7 +343,7 @@ pub(crate) mod decl { infer_variance: bool, } - #[pyclass(flags(HAS_DICT), with(AsNumber, Constructor))] + #[pyclass(flags(HAS_DICT), with(AsNumber, Constructor, Representable))] impl ParamSpec { #[pymethod] fn __mro_entries__(&self, _bases: PyObjectRef, vm: &VirtualMachine) -> PyResult { @@ -555,6 +555,14 @@ pub(crate) mod decl { } } + impl Representable for ParamSpec { + #[inline(always)] + fn repr_str(zelf: &crate::Py, vm: &VirtualMachine) -> PyResult { + let name = zelf.__name__().str(vm)?; + Ok(format!("~{}", name)) + } + } + pub(crate) fn make_paramspec(name: PyObjectRef) -> ParamSpec { ParamSpec { name, From 56403650bea6a68a905a5faec54cb5a786ec7462 Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Fri, 27 Jun 2025 20:39:27 +0900 Subject: [PATCH 2/2] Fix more repr --- Lib/test/test_typing.py | 8 -------- vm/src/stdlib/typing.rs | 6 +++--- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py index 61dc0a5e4c..44007f2501 100644 --- a/Lib/test/test_typing.py +++ b/Lib/test/test_typing.py @@ -1436,8 +1436,6 @@ class G2(Generic[Unpack[Ts]]): pass with self.assertRaises(TypeError): C[int, Unpack[Ts], Unpack[Ts]] - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_repr_is_correct(self): Ts = TypeVarTuple('Ts') @@ -1555,8 +1553,6 @@ class A(Generic[Unpack[Ts]]): pass self.assertEndsWith(repr(K[float]), 'A[float, typing.Unpack[typing.Tuple[str, ...]]]') self.assertEndsWith(repr(K[float, str]), 'A[float, str, typing.Unpack[typing.Tuple[str, ...]]]') - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_cannot_subclass(self): with self.assertRaisesRegex(TypeError, NOT_A_BASE_TYPE % 'TypeVarTuple'): class C(TypeVarTuple): pass @@ -3634,8 +3630,6 @@ def test_new_repr_complex(self): 'typing.List[typing.Tuple[typing.List[int], typing.List[int]]]' ) - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_new_repr_bare(self): T = TypeVar('T') self.assertEqual(repr(Generic[T]), 'typing.Generic[~T]') @@ -4300,8 +4294,6 @@ class Y(C[int]): self.assertEqual(Y.__qualname__, 'GenericTests.test_repr_2..Y') - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_repr_3(self): T = TypeVar('T') T1 = TypeVar('T1') diff --git a/vm/src/stdlib/typing.rs b/vm/src/stdlib/typing.rs index e9cd1cf270..9f0764e81d 100644 --- a/vm/src/stdlib/typing.rs +++ b/vm/src/stdlib/typing.rs @@ -559,7 +559,7 @@ pub(crate) mod decl { #[inline(always)] fn repr_str(zelf: &crate::Py, vm: &VirtualMachine) -> PyResult { let name = zelf.__name__().str(vm)?; - Ok(format!("~{}", name)) + Ok(format!("~{name}")) } } @@ -747,7 +747,7 @@ pub(crate) mod decl { #[inline(always)] fn repr_str(zelf: &crate::Py, vm: &VirtualMachine) -> PyResult { let name = zelf.name.str(vm)?; - Ok(format!("*{name}")) + Ok(name.to_string()) } } @@ -968,7 +968,7 @@ pub(crate) mod decl { } #[pyattr] - #[pyclass(name)] + #[pyclass(name = "Generic", module = "typing")] #[derive(Debug, PyPayload)] #[allow(dead_code)] pub(crate) struct Generic {}