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

Do not include the double quotes in #[pyclass(name = "literal")] #1303

Merged
merged 2 commits into from
Dec 12, 2020

Conversation

scalexm
Copy link
Contributor

@scalexm scalexm commented Nov 30, 2020

Embarrassing... My previous PR was quite wrong actually, as it would set the class name to '"literal"', double quotes included :)

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, sorry for the slow review by us! I just have a couple of small final thoughts on this one...

@@ -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>,
Copy link
Member

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?

Copy link
Contributor Author

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.

Comment on lines 104 to 106
syn::Expr::Path(exp) if exp.path.segments.len() == 1 => {
self.name = Some(exp.clone().into());
self.name = Some(exp.clone());
}
Copy link
Member

@davidhewitt davidhewitt Dec 8, 2020

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?

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Member

@kngwyu kngwyu left a 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...

Comment on lines 104 to 106
syn::Expr::Path(exp) if exp.path.segments.len() == 1 => {
self.name = Some(exp.clone().into());
self.name = Some(exp.clone());
}
Copy link
Member

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.

@davidhewitt davidhewitt mentioned this pull request Dec 12, 2020
@davidhewitt
Copy link
Member

@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!

@davidhewitt
Copy link
Member

@kngwyu this branch should now be ready to merge for the release!

@kngwyu
Copy link
Member

kngwyu commented Dec 12, 2020

Thanks!

@kngwyu kngwyu merged commit 2a3a730 into PyO3:master Dec 12, 2020
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.

3 participants