From ecc59cfdcd00a9765a8ec3dccdd4c41b075d0c7d Mon Sep 17 00:00:00 2001 From: Lee Dogeon Date: Sat, 14 Feb 2026 09:17:41 +0900 Subject: [PATCH] Fix inspect.signature introspection for attrgetter/itemgetter/methodcaller (#7111) * Fix attrgetter signature introspection in operator * Fix itemgetter signature introspection in operator * Fix methodcaller signature introspection in operator --- Lib/test/test_operator.py | 12 ------------ crates/vm/src/stdlib/operator.rs | 24 +++++++++++++++++++++--- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/Lib/test/test_operator.py b/Lib/test/test_operator.py index f8b36a3c2..1f89986c7 100644 --- a/Lib/test/test_operator.py +++ b/Lib/test/test_operator.py @@ -668,18 +668,6 @@ class PyOperatorTestCase(OperatorTestCase, unittest.TestCase): class COperatorTestCase(OperatorTestCase, unittest.TestCase): module = c_operator - @unittest.expectedFailure # TODO: RUSTPYTHON - def test_attrgetter_signature(self): - return super().test_attrgetter_signature() - - @unittest.expectedFailure # TODO: RUSTPYTHON - def test_itemgetter_signature(self): - return super().test_itemgetter_signature() - - @unittest.expectedFailure # TODO: RUSTPYTHON - def test_methodcaller_signature(self): - return super().test_methodcaller_signature() - @support.thread_unsafe("swaps global operator module") class OperatorPickleTestCase: diff --git a/crates/vm/src/stdlib/operator.rs b/crates/vm/src/stdlib/operator.rs index c5fa03a12..fb0d65236 100644 --- a/crates/vm/src/stdlib/operator.rs +++ b/crates/vm/src/stdlib/operator.rs @@ -340,7 +340,8 @@ mod _operator { Ok(res) } - /// attrgetter(attr, ...) --> attrgetter object + /// attrgetter(attr, /, *attrs) + /// -- /// /// Return a callable object that fetches the given attribute(s) from its operand. /// After f = attrgetter('name'), the call f(r) returns r.name. @@ -356,6 +357,11 @@ mod _operator { #[pyclass(with(Callable, Constructor, Representable))] impl PyAttrGetter { + #[pygetset] + fn __text_signature__(&self) -> &'static str { + "(obj, /)" + } + #[pymethod] fn __reduce__(zelf: PyRef, vm: &VirtualMachine) -> PyResult<(PyTypeRef, PyTupleRef)> { let attrs = vm @@ -440,7 +446,8 @@ mod _operator { } } - /// itemgetter(item, ...) --> itemgetter object + /// itemgetter(item, /, *items) + /// -- /// /// Return a callable object that fetches the given item(s) from its operand. /// After f = itemgetter(2), the call f(r) returns r[2]. @@ -454,6 +461,11 @@ mod _operator { #[pyclass(with(Callable, Constructor, Representable))] impl PyItemGetter { + #[pygetset] + fn __text_signature__(&self) -> &'static str { + "(obj, /)" + } + #[pymethod] fn __reduce__(zelf: PyRef, vm: &VirtualMachine) -> PyObjectRef { let items = vm.ctx.new_tuple(zelf.items.to_vec()); @@ -507,7 +519,8 @@ mod _operator { } } - /// methodcaller(name, ...) --> methodcaller object + /// methodcaller(name, /, *args, **kwargs) + /// -- /// /// Return a callable object that calls the given method on its operand. /// After f = methodcaller('name'), the call f(r) returns r.name(). @@ -523,6 +536,11 @@ mod _operator { #[pyclass(with(Callable, Constructor, Representable))] impl PyMethodCaller { + #[pygetset] + fn __text_signature__(&self) -> &'static str { + "(obj, /)" + } + #[pymethod] fn __reduce__(zelf: PyRef, vm: &VirtualMachine) -> PyResult { // With no kwargs, return (type(obj), (name, *args)) tuple.