Skip to content Skip to sidebar Skip to footer
Showing posts with the label Magic Methods

Why Does Functools.lru_cache Not Cache __call__ While Working On Normal Methods

I have been trying to make functools.lru_cache instance specific as described in this answer, but t… Read more Why Does Functools.lru_cache Not Cache __call__ While Working On Normal Methods

Why Are Explicit Calls To Magic Methods Slower Than "sugared" Syntax?

I was messing around with a small custom data object that needs to be hashable, comparable, and fas… Read more Why Are Explicit Calls To Magic Methods Slower Than "sugared" Syntax?

How To Override A Magic Method For The Current Script Without A Class?

How to override a magic method for the current script? def __setattr__(name, value): __dict__[n… Read more How To Override A Magic Method For The Current Script Without A Class?

Python __index__ Special Method

>>> class Thing(object): ... def __index__(self): ... return 1 ... >>&g… Read more Python __index__ Special Method