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

Ignore syn::Type::Group in is_python #1505

Merged
merged 2 commits into from
Mar 20, 2021
Merged

Ignore syn::Type::Group in is_python #1505

merged 2 commits into from
Mar 20, 2021

Conversation

scalexm
Copy link
Contributor

@scalexm scalexm commented Mar 18, 2021

Macro expansion can add invisible delimiters around types, modelled by syn::Type::Group in syn. This causes the following code to fail to compile:

#[pyclass]
struct Foo {}

macro_rules! foo {
    (
        #[pymethods]
        impl $ty: ty {
            fn $fn:ident (&self, $arg:ident : $arg_ty:ty) {}
        }
    ) => {
        #[pymethods]
        impl $ty {
            fn $fn(&self, $arg: $arg_ty) {}
        }
    };
}

foo!(
    #[pymethods]
    impl Foo {
        fn foo(&self, py: Python<'_>) {}
    }
);

error[E0277]: the trait bound pyo3::Python<'_>: PyClass is not satisfied

because pyo3 does not "see" the special py argument.

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! I would say this needs a CHANGELOG entry, though I find it hard to express what the end-user benefit is.

Maybe "Fix use of Python argument for #[pymethods] inside macro expansions" ?

@davidhewitt
Copy link
Member

I'm going to push a CHANGELOG entry and test this morning quickly.

@davidhewitt davidhewitt merged commit 246335b into PyO3:main Mar 20, 2021
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