DEV Community

Discussion on: Functools - The Power of Higher-Order Functions in Python

Collapse
 
alexmartelli profile image
Alex Martelli

To decorate a method with cached_property, the method must be callable without arguments (just like it must be in order to decorate it with built-in property), so the example of cached_property given in the article is wrong.

The sum function the article builds with reduce is tricky, since it does NOT return the sum of the items (like the built-in sum would), but rather one more than that (as can be seen in the very example the article gives), making the function's name extremely misleading -- I recommend removing that 1 initializer!