Bug Description
CPython's slot wrappers let the caller omit a trailing argument and substitute None. Introspection emits those parameters as required, so the stub disagrees with the runtime and mypy.stubtest reports one error per method.
Affects __pow__, __rpow__ and __get__.
Steps to Reproduce
#[pyclass]
struct Number(u64);
#[pymethods]
impl Number {
fn __pow__(&self, other: &Self, modulo: Option<&Self>) -> Self {
Self(self.0.pow(other.0 as u32) % modulo.map_or(u64::MAX, |m| m.0))
}
}
Build with experimental-inspect, then generate stubs with pyo3-introspection:
def __pow__(self, other: object, modulo: object, /) -> Number: ... # generated
$ python -c "import slotrepro; print(slotrepro.Number.__pow__.__text_signature__)"
($self, value, mod=None, /)
$ python -m mypy.stubtest slotrepro
error: slotrepro.Number.__pow__ is inconsistent, runtime parameter "mod" has a default value but stub parameter does not
Stub:
def (slotrepro.Number, object, object) -> slotrepro.Number
Runtime:
def (self, value, mod=None, /)
Fix
I already worked on a fix here (#6363) but am unsure whether this implementation is really clean & good. Open for suggestions!
Bug Description
CPython's slot wrappers let the caller omit a trailing argument and substitute
None. Introspection emits those parameters as required, so the stub disagrees with the runtime andmypy.stubtestreports one error per method.Affects
__pow__,__rpow__and__get__.Steps to Reproduce
Build with
experimental-inspect, then generate stubs withpyo3-introspection:Fix
I already worked on a fix here (#6363) but am unsure whether this implementation is really clean & good. Open for suggestions!