Skip to content

Conversation

@tpoliaw
Copy link
Contributor

@tpoliaw tpoliaw commented Nov 4, 2025

The tests make use of the py_run macro which is only available with the
macros feature enabled.

While the py_run macro supports a wider range of requirements, the way
it is used in these tests is straightforward enough that it can be
replaced with a local function to prevent the macros feature needing to
be enabled.

Closes #5345

The tests make use of the py_run macro which is only available with the
macros feature enabled.
@tpoliaw tpoliaw force-pushed the ordered-float-test branch from 2804c4b to 662018b Compare November 4, 2025 23:21
@tpoliaw
Copy link
Contributor Author

tpoliaw commented Nov 4, 2025

Probably too late, I just read through the related comments on #5344 and I still think this is ok as a stand-alone change. The tests rely on the macro so requiring it makes some sense.

Would it be better to replace the macro uses so the tests run with no other features enabled or is it still clearer to use the shorthand version?

Replace the py_run macro with a local function offering a simplified but
sufficient functionality
@tpoliaw
Copy link
Contributor Author

tpoliaw commented Nov 5, 2025

Replacing the macro didn't look too bad so is possibly the better approach so the tests aren't skipped unexpectedly.

@tpoliaw tpoliaw changed the title fix: Require macros feature for ordered_float tests fix: Replace macro use in ordered_float tests Nov 7, 2025
@davidhewitt davidhewitt added the CI-skip-changelog Skip checking changelog entry label Nov 7, 2025
@davidhewitt
Copy link
Member

Thanks very much for this! Doing this got me experimenting, IIRC we gated py_run! behind the macros feature to avoid the optional dependencies.

Maybe we can simplify and do something like #5608, and then always allow py_run! macro to be defined?

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.

On balance I decided it might not be a bad thing to keep py_run! gated behind the macros feature in case we do crazy stuff in the future like move it to be a proc macro; nobody has asked for that change.

So let's merge this; thanks!

Comment on lines 111 to 118
fn py_run<'py>(py: Python<'py>, script: String, locals: impl IntoPyDict<'py>) {
py.run(
&CString::new(script).unwrap(),
None,
Some(&locals.into_py_dict(py).unwrap()),
)
.unwrap()
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
fn py_run<'py>(py: Python<'py>, script: String, locals: impl IntoPyDict<'py>) {
py.run(
&CString::new(script).unwrap(),
None,
Some(&locals.into_py_dict(py).unwrap()),
)
.unwrap()
}
fn py_run<'py>(py: Python<'py>, script: &CStr, locals: impl IntoPyDict<'py>) {
py.run(
script,
None,
Some(&locals.into_py_dict(py).unwrap()),
)
.unwrap()
}

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'll have a look at fixing the calls to work with this

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.

I think we can avoid introducing format! and use c"" literals with &Cstr instead.

@tpoliaw
Copy link
Contributor Author

tpoliaw commented Nov 21, 2025

I think we still need format in a couple of places where we're building the strings with args, but have replaced the others with cstr literals.

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.

Perfect, many thanks!

@davidhewitt davidhewitt added this pull request to the merge queue Nov 24, 2025
Merged via the queue into PyO3:main with commit 17449b5 Nov 24, 2025
42 of 43 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.

ordered-float tests fail

2 participants