-
Notifications
You must be signed in to change notification settings - Fork 784
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2739: error when `#[pyo3(signature = ())]` used on invalid methods r=davidhewitt a=davidhewitt A follow-up to #2702 to reject some invalid applications of `#[pyo3(signature = (...))]` attribute, specifically on magic methods and getters / setters / class attributes. Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
- Loading branch information
Showing
13 changed files
with
223 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
//! Check that some magic methods edge cases error as expected. | ||
//! | ||
//! For convenience use #[pyo3(name = "__some_dunder__")] to create the methods, | ||
//! so that the function names can describe the edge case to be rejected. | ||
use pyo3::prelude::*; | ||
|
||
#[pyclass] | ||
struct MyClass {} | ||
|
||
// | ||
// Argument counts | ||
// | ||
|
||
#[pymethods] | ||
impl MyClass { | ||
#[pyo3(name = "__truediv__")] | ||
fn truediv_expects_one_argument(&self) -> PyResult<()> { | ||
Ok(()) | ||
} | ||
} | ||
|
||
#[pymethods] | ||
impl MyClass { | ||
#[pyo3(name = "__truediv__")] | ||
fn truediv_expects_one_argument_py(&self, _py: Python<'_>) -> PyResult<()> { | ||
Ok(()) | ||
} | ||
} | ||
|
||
// | ||
// Forbidden attributes | ||
// | ||
|
||
#[pymethods] | ||
impl MyClass { | ||
#[pyo3(name = "__bool__", signature = ())] | ||
fn signature_is_forbidden(&self) -> bool { | ||
true | ||
} | ||
} | ||
|
||
#[pymethods] | ||
impl MyClass { | ||
#[pyo3(name = "__bool__", text_signature = "")] | ||
fn text_signature_is_forbidden(&self) -> bool { | ||
true | ||
} | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
error: Expected 1 arguments, got 0 | ||
--> tests/ui/invalid_proto_pymethods.rs:18:8 | ||
| | ||
18 | fn truediv_expects_one_argument(&self) -> PyResult<()> { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: Expected 1 arguments, got 0 | ||
--> tests/ui/invalid_proto_pymethods.rs:26:8 | ||
| | ||
26 | fn truediv_expects_one_argument_py(&self, _py: Python<'_>) -> PyResult<()> { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: `signature` cannot be used with magic method `__bool__` | ||
--> tests/ui/invalid_proto_pymethods.rs:37:31 | ||
| | ||
37 | #[pyo3(name = "__bool__", signature = ())] | ||
| ^^^^^^^^^ | ||
|
||
error: `text_signature` cannot be used with magic method `__bool__` | ||
--> tests/ui/invalid_proto_pymethods.rs:45:31 | ||
| | ||
45 | #[pyo3(name = "__bool__", text_signature = "")] | ||
| ^^^^^^^^^^^^^^ |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.