diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py index 61dc0a5e4c0..44007f25019 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 25a26015a4b..9f0764e81df 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, @@ -739,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()) } } @@ -960,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 {}