pyo3
pyo3 copied to clipboard
Detect non-subclassable class being subclassed at compile-time
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.
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...