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

Detect non-subclassable class being subclassed at compile-time #4451

Closed
ChayimFriedman2 opened this issue Aug 18, 2024 · 1 comment · Fixed by #4453
Closed

Detect non-subclassable class being subclassed at compile-time #4451

ChayimFriedman2 opened this issue Aug 18, 2024 · 1 comment · Fixed by #4453

Comments

@ChayimFriedman2
Copy link
Contributor

The following compiles, but crashes at runtime:

#[pyclass] // No `(subclass)`!
pub struct BaseClass {}

#[pyclass(extends=BaseClass)]
pub struct SubClass {}

It'd be nice if we could detect this at compile-time instead. This should be simple: make a bound that isn't true for non-subclassable classes, possibly even with a nice #[diagnostics::on_unimplemented].

I can work on this later.

@davidhewitt
Copy link
Member

A thought to consider here, should we invert this and have final instead of subclass? Imo most python users expect to be able to subclass things...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants