Re:Functional Python Programming
by stayfrosty420 on Friday June 09, 2023 @10:17AM
(#36258160)
@dataclass is the new final
[ Parent
| on HN ]
Does the type system let you express that a class shouldn't be subclassed? I remember this possibility was mentioned in a PEP and got deferred. It would be really useful with the new match/case pattern matching feature, because then you could have proper sum types, and mypy could enforce exhaustiveness. AFAIK you have to do a workaround with a "assert False" or similar at the end.
* * *
It's not what you were asking for (class that can't be subclassed), but `typing` has an `assert_never` to check exhaustiveness:
https://typing.readthedocs.io/en/latest/source/unreachable.h...