don't list data in repr
Closed this issue · 8 comments
cachetools/src/cachetools/__init__.py
Line 59 in 8b9bbc4
This is just soooo wrong!
Could you explain why you think this is the case?
PS: please don't be rude.
Could you explain why you think this is the case?
PS: please don't be rude.
large number of items output to the console whose, in turn, reprs could be big as well.
@majidaldo: It would be helpful and raise your chance of getting a timely reply if you took the effort to provide a little more detail in the first place. Anyway,
>>> d = {v: v for v in range(1, 1000000)}
>>> d
{1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7, 8: 8, 9: 9, 10: 10, 11: 11, 12: 12, 13: 13, 14: 14, 15: 15, 16: 16, ...
So if you really think this is wrong, I'd suggest opening an issue there.
@majidaldo: It would be helpful and raise your chance of getting a timely reply if you took the effort to provide a little more detail in the first place. Anyway,
>>> d = {v: v for v in range(1, 1000000)} >>> d {1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7, 8: 8, 9: 9, 10: 10, 11: 11, 12: 12, 13: 13, 14: 14, 15: 15, 16: 16, ...
So if you really think this is wrong, I'd suggest opening an issue there.
What you showed is a repr on the dictionary. The repr for the cache is list
ing the data object. What you pointed out is actually what should happen in the code: just 'pass the buck' to the data object: repr(self.__data)
.
As I commented (positively) elsewhere, this library should really encode a (complete) separation of the caching algorithm from the 'storage' object (self.__data). I've done the research and this library is best-placed for this.
@majidaldo: So, to get this straight: What you object to is actually the list
, and you'd suggest something like
def __repr__(self):
return "%s(%s, maxsize=%r, currsize=%r)" % (
self.__class__.__name__,
repr(self.__data),
self.__maxsize,
self.__currsize,
)
Did I understand you correctly?
@majidaldo: So, to get this straight: What you object to is actually the
list
, and you'd suggest something likedef __repr__(self): return "%s(%s, maxsize=%r, currsize=%r)" % ( self.__class__.__name__, repr(self.__data), self.__maxsize, self.__currsize, )
Did I understand you correctly?
correct.
Fair enough. Good catch, actually, but please try to explain yourself in more detail when opening an issue next time!
Since the format of repr
changes from
Cache([(1, 1), (2, 2)], maxsize=10, currsize=2)
to
Cache({1: 1, 2: 2}, maxsize=10, currsize=2)
this is still a breaking change and will have to wait until being considered for v5.0.0.