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

More ergonomic error messages for invalid #[pyclass] args #826

Merged
merged 2 commits into from
Mar 23, 2020

Conversation

kngwyu
Copy link
Member

@kngwyu kngwyu commented Mar 22, 2020

Resolves #823

pyo3-derive-backend/src/pyclass.rs Outdated Show resolved Hide resolved
pyo3-derive-backend/src/pyclass.rs Outdated Show resolved Hide resolved
pyo3-derive-backend/src/pyclass.rs Outdated Show resolved Hide resolved
return Err(syn::Error::new_spanned(
exp.path.clone(),
"Unsupported parameter",
));
format!("Expected one of gc/weakref/subclass/dict, but got {}", x),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could perhaps add a test for this case too?

Comment on lines 13 to 17
error: Expected type name (e.g., Name), but got m :: MyClass
--> $DIR/invalid_pyclass_args.rs:9:18
|
9 | #[pyclass(name = m::MyClass)]
| ^^^^^^^^^^
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trying to decide if the but got x portion of the error messages is necessary.

On the plus side, they make the error description slightly nicer to read.

However, the invalid "but got" input is already highlighted in the source code beneath the error, so we're kinda repeating the information twice.

Also, in this m::MyClass case the formatting has been changed versus the original source code, which makes it a bit weird to read.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @gilescope who reported the original issue.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, I chose a simplfied one.

Co-Authored-By: Georg Brandl <georg@python.org>
Copy link
Member

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks great to me!

@kngwyu kngwyu merged commit 3b8af93 into PyO3:master Mar 23, 2020
@gilescope
Copy link
Contributor

Cracking.

Sent with GitHawk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrong format error diagnostics
4 participants