Skip to content

add Sealed to pyclass traits#5845

Merged
davidhewitt merged 1 commit intoPyO3:mainfrom
luxedo:3908/seal-pyclass
Apr 24, 2026
Merged

add Sealed to pyclass traits#5845
davidhewitt merged 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 thread src/impl_/pyclass.rs Outdated
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).

Comment thread src/impl_/pyclass.rs Outdated
/// 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).

@luxedo luxedo force-pushed the 3908/seal-pyclass branch from 40de57d to a2d5930 Compare April 1, 2026 01:48
@davidhewitt
Copy link
Copy Markdown
Member

Thanks, I think if you merge main CI will be green.

@luxedo luxedo force-pushed the 3908/seal-pyclass branch from a2d5930 to 4cba28d Compare April 14, 2026 15:48
@luxedo luxedo force-pushed the 3908/seal-pyclass branch from 4cba28d to a99c305 Compare April 15, 2026 00:10
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 15, 2026

Merging this PR will degrade performance by 10.73%

❌ 1 regressed benchmark
✅ 104 untouched benchmarks
⏩ 1 skipped benchmark1

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
bench_pyclass_create 3.9 µs 4.4 µs -10.73%

Comparing luxedo:3908/seal-pyclass (a99c305) with main (962a535)

Open in CodSpeed

Footnotes

  1. 1 benchmark was skipped, so the baseline result was used instead. If it was deleted from the codebase, click here and archive it to remove it from the performance reports.

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!

@davidhewitt davidhewitt added this pull request to the merge queue Apr 23, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Apr 23, 2026
@davidhewitt davidhewitt added this pull request to the merge queue Apr 24, 2026
Merged via the queue into PyO3:main with commit d0ddb78 Apr 24, 2026
45 of 46 checks passed
davidhewitt pushed a commit to davidhewitt/pyo3 that referenced this pull request May 1, 2026
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