pyo3 icon indicating copy to clipboard operation
pyo3 copied to clipboard

Seal traits inside `impl_` submodule

Open davidhewitt opened this issue 1 year ago • 8 comments

Off the back of https://github.com/PyO3/pyo3/pull/3897#discussion_r1504721475

Should we review the traits inside the impl_ submodule, check which ones can be sealed, and do that? It's a reasonable safety mechanism to prevent users from trying to implement those things.

davidhewitt avatar Feb 27 '24 19:02 davidhewitt

I labelled this "Good First Issue", as this is an internal refactoring which would be great to have.

A "sealed" trait has a private supertrait, thus making it possible to implement outside the crate. All of the PyAnyMethods and similar traits are sealed, for example. Take a look at src/sealed.rs as the trait we use as the supertrait for most sealing.

davidhewitt avatar Apr 02 '24 21:04 davidhewitt

@davidhewitt I am happy to have a look at this

Cheukting avatar Jun 14 '24 09:06 Cheukting

Brilliant, thanks 🙏

davidhewitt avatar Jun 14 '24 10:06 davidhewitt

@davidhewitt quick question, are there any particular reasons something should be or should not be moved? Or is it ideally everything should be moved from impl_ to Sealed? I want to make sure I fully understand this.

Cheukting avatar Jun 15 '24 09:06 Cheukting

I don't think we should be moving any code, this issue is about upgrading trait Foo to trait Foo: Sealed where it makes sense to do so for the traits inside the impl_ submodule.

davidhewitt avatar Jun 15 '24 10:06 davidhewitt

I see, so those traits that could be used by the user need to be Sealed right? Thanks for clarifying it @davidhewitt

Cheukting avatar Jun 15 '24 10:06 Cheukting

Yes, in principle many things inside impl_ are accessible by users but we never intend them to use them directly (just via the macros). The worry is there might be traits in there which we would prefer users can't implement at all, hence the sealing.

davidhewitt avatar Jun 15 '24 14:06 davidhewitt

Thank you for your patience, I was occupied by EuroPython preparation in the last few weeks. I plan to pick this one up again this weekend or next week.

Cheukting avatar Jul 13 '24 08:07 Cheukting