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!
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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-inproperty
), so the example ofcached_property
given in the article is wrong.The
sum
function the article builds withreduce
is tricky, since it does NOT return the sum of the items (like the built-insum
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 that1
initializer!