Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

text_signature not available for #pyclass #4586

Open
piotryordanov opened this issue Sep 30, 2024 · 5 comments
Open

text_signature not available for #pyclass #4586

piotryordanov opened this issue Sep 30, 2024 · 5 comments
Labels

Comments

@piotryordanov
Copy link

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_
@davidhewitt
Copy link
Member

#[pyo3(text_signature = "(index=1)"] should go on your #[new] function since PyO3 0.19.

@davidhewitt davidhewitt closed this as not planned Won't fix, can't repro, duplicate, stale Sep 30, 2024
@piotryordanov
Copy link
Author

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

@davidhewitt
Copy link
Member

Ah, thanks for flagging - docs need fixing!

@davidhewitt davidhewitt reopened this Sep 30, 2024
@piotryordanov
Copy link
Author

@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)

@davidhewitt
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants