From 22ad2b0e175886429d01ab50ce8d8ce79c9cc8da Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Sun, 27 Sep 2020 15:00:27 -0700 Subject: [PATCH] Simplify DebugToolbar.store() django.utils.datastructures.SortedDict has been unused since a0569d7b473a2292afbda35b4066bc0aa4429823. Can access class variables using self so drop unnecessary type() call. range() supports passing a first argument larger than the second, in which case it doesn't yield and values. >>> list(range(2, 1)) [] --- debug_toolbar/toolbar.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/debug_toolbar/toolbar.py b/debug_toolbar/toolbar.py index c1f35b02c..85757d3e9 100644 --- a/debug_toolbar/toolbar.py +++ b/debug_toolbar/toolbar.py @@ -92,15 +92,9 @@ def store(self): if self.store_id: return self.store_id = uuid.uuid4().hex - cls = type(self) - cls._store[self.store_id] = self - for _ in range(len(cls._store) - self.config["RESULTS_CACHE_SIZE"]): - try: - # collections.OrderedDict - cls._store.popitem(last=False) - except TypeError: - # django.utils.datastructures.SortedDict - del cls._store[cls._store.keyOrder[0]] + self._store[self.store_id] = self + for _ in range(self.config["RESULTS_CACHE_SIZE"], len(self._store)): + self._store.popitem(last=False) @classmethod def fetch(cls, store_id):