What's the best way to minimize the need of run time checks?

Steven D'Aprano steve+python at pearwood.info
Fri Aug 12 21:13:21 EDT 2016


On Sat, 13 Aug 2016 08:12 am, Lawrence D’Oliveiro wrote:

> On Friday, August 12, 2016 at 9:39:11 PM UTC+12, BartC wrote:
> 
>> 'year' has been spelled wrongly
> 
> That’s why Python has __slots__.

No, that is OFFICIALLY *not* why Python has __slots__.

Python has __slots__ in order to support applications where you have huge
numbers of small objects where the collective memory used by millions of
unused __dicts__ is significant.

You may choose to (ab)use __slots__ to avoid the caller adding new
attributes to your objects, but that practice is discouraged.




-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.




More information about the Python-list mailing list