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 and raw identifiers don't interact well #1285

Closed
roblabla opened this issue Nov 19, 2020 · 0 comments · Fixed by #1286
Closed

text_signature and raw identifiers don't interact well #1285

roblabla opened this issue Nov 19, 2020 · 0 comments · Fixed by #1286
Labels

Comments

@roblabla
Copy link
Contributor

roblabla commented Nov 19, 2020

🐛 Bug Reports

The text_signature attributes automatically sets the first line of the python documentation to the function signature, which is supposed to be fnname(arg1, arg2). However, this seems to interact badly with rust's raw identifiers. For instance, a methods defined like this:

#[pymethods]
impl PythonStuff {
    #[text_signature = "()"]
    fn r#match(&self) {}
}

Will have a signature of r#match() instead of the correct match(). This breaks several tools, like sphinx documentation generation.

wrongly documents match's signature as r#match() instead of simply match(). Python script showcasing the issue:

>>> import pyo3_bug
>>> help(pyo3_bug.PythonStuff.match)
Help on method_descriptor:

match(...)
    r#match()
    --

🌍 Environment

  • Your operating system and version: Ubuntu 20
  • Your python version: Python 3.8.5
  • How did you install python (e.g. apt or pyenv)? Did you use a virtualenv?: apt, yes
  • Your Rust version (rustc --version): 1.47.0
  • Your PyO3 version: 0.12
  • Have you tried using latest PyO3 master (replace version = "0.x.y" with git = "https://github.com/PyO3/pyo3")?: yes, same issue.

💥 Reproducing

Here's a quick script that will quickly reproduce the bug. It creates a simple pyo3 module with the r#match method and tries to access its help text.

cargo new --lib pyo3_bug
cd pyo3_bug
echo 'pyo3 = { version = "0.12", features = ["extension-module"] }' >> Cargo.toml
echo '[lib]' >> Cargo.toml
echo 'crate-type = ["rlib", "cdylib"]' >> Cargo.toml
cat > src/lib.rs << HERE
use pyo3::prelude::*;
#[pymodule]
fn pyo3_bug(_py: Python, m: &PyModule) -> PyResult<()> {
    m.add_class::<PythonStuff>()?;
    Ok(())
}
#[pyclass]
struct PythonStuff {}
#[pymethods]
impl PythonStuff {
    #[text_signature = "()"]
    fn r#match(&self) {}
}
HERE
maturin develop
cat << HERE | python3
import pyo3_bug
help(pyo3_bug.PythonStuff.match)
HERE

This script should eventually show:

Help on method_descriptor:

match(...)
    r#match()
    --
roblabla added a commit to roblabla/pyo3 that referenced this issue Nov 19, 2020
roblabla added a commit to roblabla/pyo3 that referenced this issue Nov 19, 2020
roblabla added a commit to roblabla/pyo3 that referenced this issue Nov 19, 2020
roblabla added a commit to roblabla/pyo3 that referenced this issue Nov 19, 2020
roblabla added a commit to roblabla/pyo3 that referenced this issue Nov 19, 2020
davidhewitt pushed a commit to roblabla/pyo3 that referenced this issue Nov 20, 2020
kngwyu added a commit that referenced this issue Nov 20, 2020
Fix #1285, text_signature and raw ident interaction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants