-
Notifications
You must be signed in to change notification settings - Fork 734
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve error messages for #[pyfunction] defined inside #[pymethods]
Make error message more specific when `#[pyfunction]` is used in `#[pymethods]`. Effectively, this replaces the error message: ``` error: static method needs #[staticmethod] attribute ``` To: ``` functions inside #[pymethods] do not need to be annotated with #[pyfunction] ``` Fixes #4340 Co-authored-by: László Vaskó <[email protected]>
- Loading branch information
Showing
5 changed files
with
70 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Improve error messages for `#[pyfunction]` defined inside `#[pymethods]` |
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,15 @@ | ||
|
||
|
||
#[pyo3::pymodule] | ||
mod pyo3_scratch { | ||
use pyo3::prelude::*; | ||
|
||
#[pyclass] | ||
struct Foo {} | ||
|
||
#[pymethods] | ||
impl Foo { | ||
#[pyfunction] | ||
fn bug() {} | ||
} | ||
} |
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,38 @@ | ||
error: module is not supported in `trait`s or `impl`s | ||
--> tests/ui/invalid_pyfunction_definition.rs:12:9 | ||
| | ||
12 | #[pyfunction] | ||
| ^^^^^^^^^^^^^ | ||
| | ||
= help: consider moving the module out to a nearby module scope | ||
= note: this error originates in the attribute macro `pyfunction` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: implementation is not supported in `trait`s or `impl`s | ||
--> tests/ui/invalid_pyfunction_definition.rs:12:9 | ||
| | ||
12 | #[pyfunction] | ||
| ^^^^^^^^^^^^^ | ||
| | ||
= help: consider moving the implementation out to a nearby module scope | ||
= note: this error originates in the attribute macro `pyfunction` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: functions inside #[pymethods] do not need to be annotated with #[pyfunction] | ||
--> tests/ui/invalid_pyfunction_definition.rs:12:9 | ||
| | ||
12 | #[pyfunction] | ||
| ^ | ||
|
||
error[E0425]: cannot find value `bug` in this scope | ||
--> tests/ui/invalid_pyfunction_definition.rs:13:12 | ||
| | ||
13 | fn bug() {} | ||
| ^^^ | ||
| | | ||
| an associated function by that name is available on `Self` here | ||
| not found in this scope | ||
|
||
error[E0601]: `main` function not found in crate `$CRATE` | ||
--> tests/ui/invalid_pyfunction_definition.rs:15:2 | ||
| | ||
15 | } | ||
| ^ consider adding a `main` function to `$DIR/tests/ui/invalid_pyfunction_definition.rs` |