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

Thread pyo3's path through the builder functions #3907

Merged
merged 2 commits into from
Mar 4, 2024

Conversation

mejrs
Copy link
Member

@mejrs mejrs commented Feb 27, 2024

The first part of addressing #3903

This gets rid of all the use #krate as _pyo3 in our macro code.

I did not address the use #pyo3_path::prelude::PyAnyMethods; imports because that looks like a lot of work so splitting it up seemed like a good idea.

@mejrs mejrs added the CI-skip-changelog Skip checking changelog entry label Feb 27, 2024
@mejrs mejrs force-pushed the non_local_definitions branch from d407acb to 5ca78a7 Compare February 27, 2024 14:44
@mejrs
Copy link
Member Author

mejrs commented Feb 27, 2024

Apparently this does something weird with the spans in some error messages. Any ideas on how to fix that?

@davidhewitt
Copy link
Member

Uff, that does not surprise me. I'll try to read and think later ASAP, but I'm currently preparing & rehearsing material for a meetup on Thursday (presenting on PyO3!) so worst case I may not be able to give this headspace until Friday.

Comment on lines +167 to +174
impl PyO3CratePath {
pub fn to_tokens_spanned(&self, span: Span) -> TokenStream {
match self {
Self::Given(path) => quote::quote_spanned! { span => #path },
Self::Default => quote::quote_spanned! { span => ::pyo3 },
}
}
}
Copy link
Member

Choose a reason for hiding this comment

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

The idea of adding this here is that this gave back control to the span that the ::pyo3 default path was being emitted with.

I applied in manually in the places where it mattered. If we wanted to force ourselves to think about it we could remove quote::ToTokens implementation and require ourselves to always call this method. I quite like the convenience of the ToTokens implementation though :)

@davidhewitt
Copy link
Member

Great - @mejrs I needed to play around with this to get a sense of what might solve this. It ended up being pretty reasonable so I pushed that as an additional commit. Hopefully that unblocks making the rest of the PR work (I see we made a few merge conflicts already since you started this 🙈).

@mejrs mejrs force-pushed the non_local_definitions branch from a72ea70 to 2838c15 Compare March 3, 2024 16:39
@mejrs mejrs force-pushed the non_local_definitions branch from 2838c15 to 2e0686e Compare March 3, 2024 16:47
@mejrs
Copy link
Member Author

mejrs commented Mar 3, 2024

Hopefully that unblocks making the rest of the PR work (I see we made a few merge conflicts already since you started this 🙈).

They have been resolved.

I'd like to merge this as is (if Ci clears 🙏 ), and address the rest in their own PR.

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 just had a full read through, looks good to me!

I agree, let's merge this given the huge potential for this to conflict and you've already had to resolve conflicts once.

Comment on lines +685 to +693
quotes::map_result_into_ptr(
quotes::ok_wrap(
quote! {
::std::clone::Clone::clone(&(#slf.#field_token))
},
ctx,
),
ctx,
)
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if it makes sense for future refactoring like moving these quotes functions to be methods on Ctx. A follow up for anyone interested I think, rather than part of this PR.

@@ -31,4 +31,4 @@ error[E0592]: duplicate definitions with name `__pymethod___richcmp____`
| duplicate definitions for `__pymethod___richcmp____`
| other definition for `__pymethod___richcmp____`
|
= note: this error originates in the macro `_pyo3::impl_::pyclass::generate_pyclass_richcompare_slot` which comes from the expansion of the attribute macro `pymethods` (in Nightly builds, run with -Z macro-backtrace for more info)
= note: this error originates in the macro `::pyo3::impl_::pyclass::generate_pyclass_richcompare_slot` which comes from the expansion of the attribute macro `pymethods` (in Nightly builds, run with -Z macro-backtrace for more info)
Copy link
Member

Choose a reason for hiding this comment

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

TBH this error looks better than the previous form 👍

@davidhewitt davidhewitt added this pull request to the merge queue Mar 4, 2024
Merged via the queue into PyO3:main with commit 4114dcb Mar 4, 2024
42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI-skip-changelog Skip checking changelog entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants