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
This commit is contained in:
Lee Dogeon authored and GitHub committed 2026-02-14 09:17:41 +09:00
1 parent 8ea96fb540
commit ecc59cfdcd
2 files changed
+21 -15

No files matched your search

-12
View File
@@ -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:
+21 -3
View File
@@ -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<Self>, 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<Self>, 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<Self>, vm: &VirtualMachine) -> PyResult<PyTupleRef> {
// With no kwargs, return (type(obj), (name, *args)) tuple.