Skip to content

Commit

Permalink
Fix PyO3#1285, text_signature and raw ident interaction
Browse files Browse the repository at this point in the history
  • Loading branch information
roblabla committed Nov 19, 2020
1 parent dcca3f8 commit f73b727
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Fixed
- Fix missing field in `PyCodeObject` struct (`co_posonlyargcount`) - caused invalid access to other fields in Python >3.7. [#1260](https://github.com/PyO3/pyo3/pull/1260)
- Fix building for `x86_64-unknown-linux-musl` target from `x86_65-unknown-linux-gnu` host. [#1267](https://github.com/PyO3/pyo3/pull/1267)
- Fix `#[text_signature]` interacting badly with rust `r#raw_identifiers`. [#1286](https://github.com/PyO3/pyo3/pull/1286)

## [0.12.3] - 2020-10-12
### Fixed
Expand Down
2 changes: 1 addition & 1 deletion pyo3-derive-backend/src/method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ impl<'a> FnSpec<'a> {

let text_signature = match &fn_type {
FnType::Fn(_) | FnType::FnClass | FnType::FnStatic => {
utils::parse_text_signature_attrs(&mut *meth_attrs, name)?
utils::parse_text_signature_attrs(&mut *meth_attrs, &python_name)?
}
FnType::FnNew => parse_erroneous_text_signature(
"text_signature not allowed on __new__; if you want to add a signature on \
Expand Down
25 changes: 25 additions & 0 deletions tests/test_text_signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,28 @@ fn test_methods() {
"typeobj.static_method.__text_signature__ == '(d)'"
);
}

#[test]
fn test_raw_identifiers() {
#[pyclass]
#[text_signature = "($self)"]
struct r#MyClass {}

#[pymethods]
impl MyClass {
#[text_signature = "($self)"]
fn r#method(&self) {}
}

let gil = Python::acquire_gil();
let py = gil.python();
let typeobj = py.get_type::<MyClass>();

py_assert!(py, typeobj, "typeobj.__text_signature__ == '($self)'");

py_assert!(
py,
typeobj,
"typeobj.method.__text_signature__ == '($self)'"
);
}

0 comments on commit f73b727

Please sign in to comment.