Skip to content

Commit

Permalink
Merge pull request #1286 from roblabla/fix-1285
Browse files Browse the repository at this point in the history
Fix #1285, text_signature and raw ident interaction
  • Loading branch information
kngwyu authored Nov 20, 2020
2 parents d3f993a + d479b54 commit 096b0a3
Show file tree
Hide file tree
Showing 3 changed files with 32 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 @@ -237,7 +237,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
30 changes: 30 additions & 0 deletions tests/test_text_signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,33 @@ fn test_methods() {
"typeobj.static_method.__text_signature__ == '(d)'"
);
}

#[test]
#[cfg_attr(all(Py_LIMITED_API, not(Py_3_10)), ignore)]
fn test_raw_identifiers() {
#[pyclass]
#[text_signature = "($self)"]
struct r#MyClass {}

#[pymethods]
impl MyClass {
#[new]
fn new() -> MyClass {
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 096b0a3

Please sign in to comment.