-3

I have task to use decorators in class methods. Without them it worked but now it require positional argument at object initialization. What's my mistake?

from collections import OrderedDict
class LRUCache:
    def __init__(self, capacity: int):
        self.cache = OrderedDict()
        self.capacity = capacity
    @property
    def cache(self):
        return self.cache
    @cache.setter
    def cache(self, key_value) -> None:
        key, value = key_value
        self.__cache[key] = value
        self.__cache.move_to_end(key)
        if len(self.__cache) > self.capacity:
            self.__cache.popitem(last=False)
cache = LRUCache(2)
cache.cache = ("key1", "value1")
cache.cache = ("key2", "value2")
cache.cache = ("key3", "value3")
Alexander
  • 5
  • 3
  • 1
    Do not post code as image. – Itération 122442 Aug 22 '23 at 17:48
  • Please post code, data, and results as text, not screenshots ([how to format code in posts](https://stackoverflow.com/help/formatting)). [Why should I not upload images of code/data/errors?](https://meta.stackoverflow.com/questions/285551/why-should-i-not-upload-images-of-code-data-errors) http://idownvotedbecau.se/imageofcode – Barmar Aug 22 '23 at 17:51
  • 1
    A property can't have any parameters other than `self`. You access it like an attribute, so there's no way to pass the `key` argument. – Barmar Aug 22 '23 at 17:53
  • Thank you for your reply. I've done what you asked – Alexander Aug 22 '23 at 21:08

0 Answers0