logoalt Hacker News

kannanvijayan • today at 2:47 PM • 1 reply • view on HN

Ah, the `__slots__` feature makes it make a lot more sense.

> Sorry, that sounds a bit vague and not too different from what CPython already is doing.

With slots being available, I can see where I was misled. I went looking for a type structure that modeled the dynamic properties on an object which would be used as a typeguard, but the class itself functions as that if you're restricting the optimization to slotted properties.

Appreciate the clarfication!


Replies

adrian17 • today at 3:08 PM

(Note that this optimization can also trigger for plain classes (that’s LOAD_ATTR_INSTANCE_VALUE), it just needs a bit more guards and is only useful if you don’t abuse instances being dynamic objects. I just used slots as the most obvious example, but there are lots of different op specializations since like 3.11)