Skip to content

add Sealed to pyclass traits#5845

Open
luxedo wants to merge 1 commit intoPyO3:mainfrom
luxedo:3908/seal-pyclass
Open

add Sealed to pyclass traits#5845
luxedo wants to merge 1 commit intoPyO3:mainfrom
luxedo:3908/seal-pyclass

Conversation

@luxedo
Copy link
Copy Markdown
Contributor

@luxedo luxedo commented Feb 28, 2026

Part of #3908

Adds Sealed to traits in impl_/pyclass.rs

@davidhewitt davidhewitt added the CI-skip-changelog Skip checking changelog entry label Mar 25, 2026
Copy link
Copy Markdown
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, a couple of these seals are probably not needed, the rest look good to me!

Comment on lines +1138 to +1144
mod pyclass_base_type {
use crate::impl_::pyclass::PyClassBaseType;

pub trait Sealed {}

impl<T: PyClassBaseType> Sealed for T {}
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This seal doesn't achieve anything it seals PyClassBaseType so creates circular logic.

I think it's ok to leave this trait un-sealed, any user-defined type could in principle implement it (maybe let's document it as such).

/// Users are discouraged from implementing this trait manually; it is a PyO3 implementation detail
/// and may be changed at any time.
pub trait PyClassImpl: Sized + 'static {
pub trait PyClassImpl: Sized + 'static + generic_pyclass::Sealed {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It is expected for user-defined types to implement this trait (via the macros), so there's no point sealing it (it's not a closed set of implementations).

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