4 ms·
This is precisely the thing I do not want from python. Subclassing is super useful in convoluted tests where fakes are superior to mocks. I don't like being tol
by 3pt14159 5y ago
This is precisely the thing I do not want from python. Subclassing is super useful in convoluted tests where fakes are superior to mocks. I don't like being told "you can't do this" by some library's code.
- scoopertrooper 5y agoIf it's enforced at the type-level then, don't check types during your test runs? shrugs
- _dain_ 5y agoIt would be enforced by the optional static type checker, not the language runtime.
- Spivak 5y agoAnd if you want to enforce it at runtime you already can! class Final(type): def __new__(cls, name, bases, dct): if any(isinstance(base, Final) for base in bases): raise TypeError("No!") return type.__new__(cls, name, bases, dct) class NoSubclasses(metaclass=Final): pass class WillThrow(NoSubclasses): pass
- deleted 5y ago[deleted]
- wasyl 5y agoFrom my experience with Kotlin, sealed classes aren't really used for classes you'd like to fake in tests - they're usually used to have an exhaustive list of data types with different parameters, basically enums on steroids. Kotlin has recently added support for sealed interfaces, which would potentially suffer from the issue you described, but I haven't found a compelling use case (or any usage in wild) for sealed interfaces. If anything, I'd expect it to be used for types that explicitly shouldn't be faked by the library consumer anyway