0
@cached_property def my_collection(): return [1, 2, 3] def do_stuff(): for i in my_collection: print i 

I try to cache a list, set or map that I can iterate on. However, doing that, I get TypeError: 'cached_property' object is not iterable. Any other workarounds?

2
  • Are you referring to the django cached_property util? Commented May 3, 2017 at 1:04
  • Yes............ Commented May 3, 2017 at 1:06

1 Answer 1

1

The reason is you are trying to apply this decorator to a function, but it makes no sense, because it's designed for instance methods. This will work:

class Foo: @cached_property def my_collection(self): return [1, 2, 3] def do_stuff(): for i in Foo().my_collection: print i 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.