Guido van Rossum <guido@python.org> writes: > > > It could make a subclass, though... > > > If the type is carefully designed, it can't... > > I suppose you have something in mind like this (which is the only way > I can come up with to implement something like a 'final' class in pure > Python): I was actually thinking about impure Python, i.e. by means of omitting Py_TPFLAGS_BASETYPE. > But how would you prevent this? > > >>> a = C() > >>> a.__class__ = D > >>> For the issue at hand: Assigning __class__ won't change the object layout, so if the object didn't have an __dict__ before, it won't have an __dict__ afterwards. Of course, if there are writable slots, the application could corrupt the underlying resource reference, making __del__ meaningless, anyway. Here I need to bring up Python's "we are all consenting adults" attitude... Regards, Martin
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4