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

fixes #4285 -- allow full-path to pymodule with nested declarative modules #4288

Merged
merged 1 commit into from
Jul 5, 2024

Conversation

alex
Copy link
Contributor

@alex alex commented Jun 26, 2024

fixes #4285

@alex alex force-pushed the full-path-pymodule branch from 1fe731d to d115719 Compare June 26, 2024 04:04
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, this is definitely worth solving.

I'd prefer a more complete solution. I think also this needs similar treatment for #[pyclass] and #[pyfunction]?

I wonder whether a more thorough alternative solution would be to immediately parse and expand inner #[pyclass] / #[pyfunction] / #[pymodule] macros. I don't know if there's any implications of expansion ordering related to that.

Actually now that I say this - I guess declarative modules will fail to see a structure like this already:

#[pymodule]
mod foo {
    macro_rules! class {
        ($name:ident) {
            #[pyclass]
            struct $name { }
        }
    }
    
    class!(Foo);
    class!(Bar);
}

item.span() => "`#[pymodule_export]` may only be used on `use` statements"
);
if has_attribute(&item_mod.attrs, "pymodule") {
if has_attribute(&item_mod.attrs, &["pymodule"])
|| has_attribute(&item_mod.attrs, &["pyo3", "prelude", "pymodule"])
Copy link
Member

Choose a reason for hiding this comment

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

We should probably use ctx.pyo3_path instead of pyo3 hard-coded here.

pyo3::pymodule is also a valid path to the macro, so we should allow that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, moved too fast, it's not clear what the best way to get an &str out of the syn::Path is. This may need more involved surgery.

@alex alex force-pushed the full-path-pymodule branch from d115719 to ed72155 Compare June 26, 2024 11:02
@alex
Copy link
Contributor Author

alex commented Jun 26, 2024

Hmm, how would expanding the macros eagerly work? Handling the variety of different forms a user can write this in is... expansive. (A user can use pyo3::prelude as foo; which this PR obviously doesn't handle.)

@alex alex force-pushed the full-path-pymodule branch 3 times, most recently from e81419b to 0676a10 Compare July 2, 2024 12:04
@alex
Copy link
Contributor Author

alex commented Jul 2, 2024

Are there other pieces you'd like here besides expanding to pyfunction/pyclass?

@davidhewitt
Copy link
Member

I think that's just it, I see you solved the Path complication above 👍

The eager expansion / unlimited forms of use imports can be problems for the future.

@alex
Copy link
Contributor Author

alex commented Jul 2, 2024 via email

@alex alex force-pushed the full-path-pymodule branch from 0676a10 to e232ef1 Compare July 2, 2024 21:35
@alex
Copy link
Contributor Author

alex commented Jul 2, 2024

Ok, added!

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.

Looks fine to me, thanks!

@davidhewitt davidhewitt added this pull request to the merge queue Jul 5, 2024
Merged via the queue into PyO3:main with commit 9afc38a Jul 5, 2024
41 of 42 checks passed
@alex alex deleted the full-path-pymodule branch July 5, 2024 12:34
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.

Declarative modules submodules don't work with #[pyo3::prelude::pymodule]
2 participants