mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 10:44:36 +08:00
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:
1 parent
8ea96fb540
commit
ecc59cfdcd
2 files changed
+21
-15
No files matched your search
Vendored
-12
@@ -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:
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in new issue
Block a user