Description
Documentation
https://docs.python.org/3.12/library/collections.html#ordereddict-examples-and-recipes
The documentation implements a TimeBoundedLRU
and a MultiHitLRUCache
with OrderedDict
. Both implementations contain self.cache.popitem(0)
where self.cache
is an OrderedDict
instance. However, method popitem()
actually takes a boolean argument indicating whether to pop from the left end or the right end of the OrderedDict
instance. Though 0
means False
, using 0
will mislead readers into passing an arbitrary integer as an index to this method to pop the corresponding item from the OrderedDict. Changing 0
to False
improves clarity, and avoids complaints from a type checker. self.requests.popitem(0)
in the implementation of MultiHitLRUCache
has the same issue.
In addition, self.requests.pop(args, None)
in the implementation of MultiHitLRUCache
should be changed to self.requests.pop(args)
since the statements preceding it have already guaranteed that self.requests
has key args. This change will reduce readers' work to think about when self.requests
would not have key args.