pyo3 icon indicating copy to clipboard operation
pyo3 copied to clipboard

Detect non-subclassable class being subclassed at compile-time

Open ChayimFriedman2 opened this issue 1 year ago • 1 comments

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.

ChayimFriedman2 avatar Aug 18 '24 11:08 ChayimFriedman2

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...

davidhewitt avatar Aug 18 '24 11:08 davidhewitt