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

__new__ and __init__ get no docstring #553

Closed
twuebi opened this issue Jul 21, 2019 · 2 comments
Closed

__new__ and __init__ get no docstring #553

twuebi opened this issue Jul 21, 2019 · 2 comments

Comments

@twuebi
Copy link

twuebi commented Jul 21, 2019

I am trying to add my doc-string and an explicit signature for __new__ and __init__ to Foo:

/// Foo(arg1, arg2)
/// --
///
/// A Foo
#[pyclass(name=Foo)]
pub struct PyFoo {
    inner: Rc<RefCell<Foo>>,
}

#[pymethods]
impl PyFoo {
    /// __new__(arg1, arg2)
    /// --
    ///
    /// Construct a new Foo
    #[new]
    fn __new__(
        obj: &PyRawObject,
        arg1: Vec<&str>,
        arg2: Vec<&str>
    ) -> PyResult<()> {
...
}

So far, I'm getting the call signature of Foo via inspect.signature(Foo) or with IPython Foo? but not through help(Foo). Both __new__ and __init__ remain with their generic doc-strings and signatures defined in typeobject.c.

As far as I understand, CPython expects functions for tp_new and tp_init which is why the ml_doc fields of their PyMethodDef get discarded in pyo3::type_object::py_class_method_defs. Is there some other way to modify the doc-strings of these built-ins?

@twuebi
Copy link
Author

twuebi commented Jul 22, 2019

The init signature has been added to help(type) on some version >3.6.5 which I am on:

python/cpython@ccb5f3c#diff-cbbbf1954ca2586f5d1d6241674fab9a

It still would be nice to be able to set the doc strings though.

@davidhewitt davidhewitt added this to the 0.18 milestone Aug 22, 2022
@davidhewitt davidhewitt modified the milestones: 0.18, 0.19 Dec 27, 2022
@davidhewitt davidhewitt changed the title __new__ and __init__ get no call signature __new__ and __init__ get no doctoring Jun 16, 2023
@davidhewitt davidhewitt changed the title __new__ and __init__ get no doctoring __new__ and __init__ get no docstring Jun 16, 2023
@davidhewitt davidhewitt removed this from the 0.19 milestone Jun 16, 2023
@davidhewitt
Copy link
Member

Closing as duplicate of the (newer, more discussed) #4326

@davidhewitt davidhewitt closed this as not planned Won't fix, can't repro, duplicate, stale Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants