-
Notifications
You must be signed in to change notification settings - Fork 760
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
Do not include the double quotes in #[pyclass(name = "literal")]
#1303
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, sorry for the slow review by us! I just have a couple of small final thoughts on this one...
pyo3-derive-backend/src/pyclass.rs
Outdated
@@ -15,7 +15,7 @@ use syn::{parse_quote, Expr, Token}; | |||
/// The parsed arguments of the pyclass macro | |||
pub struct PyClassArgs { | |||
pub freelist: Option<syn::Expr>, | |||
pub name: Option<syn::Expr>, | |||
pub name: Option<syn::ExprPath>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually wonder if this should be syn::LitStr
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could easily be LitStr
if we deprecate the other branch as you said, although it may be better not to allow arbitrary strings, so maybe Ident
is even better.
pyo3-derive-backend/src/pyclass.rs
Outdated
syn::Expr::Path(exp) if exp.path.segments.len() == 1 => { | ||
self.name = Some(exp.clone().into()); | ||
self.name = Some(exp.clone()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is the branch for name
without quotes? I would actually be quite happy to deprecate this as I think name="CustomName"
is clearer than name=CustomName
.
If you agree, we could make this branch return an error message suggesting the user wrap the name in quotes.
cc @kngwyu - do you agree with a breaking change here to tidy this up?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’d support that as well, also ExprPath
is actually too restrictive as it doesn’t play well with substituted macro variables which are basically None
delimited ExprGroup
. That was the very reason for my initial PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I agree to remove the branch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you and sorry for the lazy review, too. I just overlooked this PR...
pyo3-derive-backend/src/pyclass.rs
Outdated
syn::Expr::Path(exp) if exp.path.segments.len() == 1 => { | ||
self.name = Some(exp.clone().into()); | ||
self.name = Some(exp.clone()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I agree to remove the branch.
@scalexm I'm going to finish and force push this branch this morning, so we can include it in the release. Hope that's okay! |
@kngwyu this branch should now be ready to merge for the release! |
Thanks! |
Embarrassing... My previous PR was quite wrong actually, as it would set the class name to
'"literal"'
, double quotes included :)