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

Migrate PyTuple / PyList constructors #4580

Merged
merged 3 commits into from
Sep 29, 2024
Merged

Conversation

Icxolu
Copy link
Contributor

@Icxolu Icxolu commented Sep 26, 2024

Followup to #4559

PyList::new and PyTuple::new become fallible.

It's worth double checking the bad_clone_mem_leaks tests, to make sure I didn't accidentally change the semantics there.

@Icxolu Icxolu added the CI-skip-changelog Skip checking changelog entry label Sep 26, 2024
@Icxolu Icxolu force-pushed the migrate-sequence branch 2 times, most recently from dd87350 to 76f2250 Compare September 26, 2024 19:00
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, it seems like the correct conclusion to me that the constructors have to become fallible, even it's a small breaking change.

We should mention this explicitly in its own newsfragment, I think.

@Icxolu Icxolu removed the CI-skip-changelog Skip checking changelog entry label Sep 27, 2024
@Icxolu
Copy link
Contributor Author

Icxolu commented Sep 27, 2024

Makes sense 👍

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, looks perfect! 🚀

Just a couple of tiny thoughts.

type Error = Infallible;

fn into_pyobject(self, py: Python<'py>) -> Result<Self::Output, Self::Error> {
self.clone().0.into_pyobject(py)
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 whether it's simpler to remove Clone from the picture and instead just have the panic produced in here?

IIRC, the main point of the test is to check that panics while constructing the list free stuff properly, Clone was probably just the bug report which came in or similar.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I think that makes it a bit clearer. I changed this, removed the now unnecessary cfg and renamed the test (also for PyTuple)

}

#[inline]
#[track_caller]
pub(crate) fn try_new_from_iter<'py>(
py: Python<'py>,
elements: &mut dyn ExactSizeIterator<Item = PyResult<PyObject>>,
elements: &mut dyn ExactSizeIterator<Item = PyResult<Bound<'py, PyAny>>>,
Copy link
Member

Choose a reason for hiding this comment

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

Do you think it's worth making these have a concrete iterator? I forget why we had to change it for sets 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean impl instead of dyn here? Or what concrete type are you referring to?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, impl Iterator

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.

Super, thanks 👍

I'll seek to get to the other reviews waiting on me either tonight or tomorrow evening

@davidhewitt davidhewitt added this pull request to the merge queue Sep 29, 2024
Merged via the queue into PyO3:main with commit 2fa97f9 Sep 29, 2024
43 checks passed
@Icxolu Icxolu deleted the migrate-sequence branch September 29, 2024 08:30
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.

2 participants