`text_signature` not available for `#pyclass`
Bug Description
I expect to be able to add the text_signature to the pyclass, but it's failing.
Running pyo3 version 0.22.3.
Steps to Reproduce
#[pyclass(text_signature = "(index=1)")]
#[derive(Debug, Clone)]
pub struct Signal {
pub index: i32,
}
Backtrace
error: expected one of: `crate`, `dict`, `eq`, `eq_int`, `extends`, `freelist`, `frozen`, `get_all`, `hash`, `mapping`, `module`, `name`, `ord`, `rename_all`, `sequence`, `set_all`, `subclass`, `unsendable`, `weakref`
### Your operating system and version
arch
### Your Python version (`python --version`)
3.10.12
### Your Rust version (`rustc --version`)
1.71.1
### Your PyO3 version
0.22.3
### How did you install python? Did you use a virtualenv?
python env is managed by rye
### Additional Info
_No response_
#[pyo3(text_signature = "(index=1)"] should go on your #[new] function since PyO3 0.19.
Ah that solves it. Thx for the fast reply.
What confused me was that it's still mentioned as a valid option in here and here
Ah, thanks for flagging - docs need fixing!
@davidhewitt I tried the change you suggested, but for some reason, it's not propagatd to python.
#[pymethods]
impl Signal {
/// This is a signal that does xyz
#[new]
#[pyo3(text_signature = "(index)")]
fn new(index: i32) -> Self {
Signal { index }
}
And in python, the signature for __new__ shows as:
($type, *args, **kwargs)
The text signature ends up just below the class header, rather than on the __new__ help, e.g.:
Help on class Foo in module pyo3_scratch:
class Foo(builtins.object)
| Foo(index, /) <----- here
To put it on __new__, would require the same kind of solution as in #4326