Mercurial > hg
diff mercurial/util.py @ 46901:51841b23670b
typing: make minor adjustments to mercurial/util.py to pass pytype checking
I'm assuming the wrong-arg-count is a pytype bug, because this code is used by
the config object. Avoiding initializing `_lrucachenode` node points to None
eliminates a few `is not None` assertions, but apparently not all of them. I
can't figure out why it gets confused over the state where these new assertions
are.
Differential Revision: https://phab.mercurial-scm.org/D10276
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Thu, 25 Mar 2021 22:29:41 -0400 |
parents | 64400d05db1e |
children | 856820b497fc |
line wrap: on
line diff
--- a/mercurial/util.py Thu Mar 25 20:22:00 2021 -0400 +++ b/mercurial/util.py Thu Mar 25 22:29:41 2021 -0400 @@ -1265,7 +1265,8 @@ """call this before writes, return self or a copied new object""" if getattr(self, '_copied', 0): self._copied -= 1 - return self.__class__(self) + # Function cow.__init__ expects 1 arg(s), got 2 [wrong-arg-count] + return self.__class__(self) # pytype: disable=wrong-arg-count return self def copy(self): @@ -1408,8 +1409,8 @@ __slots__ = ('next', 'prev', 'key', 'value', 'cost') def __init__(self): - self.next = None - self.prev = None + self.next = self + self.prev = self self.key = _notset self.value = None @@ -1448,9 +1449,7 @@ def __init__(self, max, maxcost=0): self._cache = {} - self._head = head = _lrucachenode() - head.prev = head - head.next = head + self._head = _lrucachenode() self._size = 1 self.capacity = max self.totalcost = 0 @@ -1555,6 +1554,7 @@ """ try: node = self._cache[k] + assert node is not None # help pytype return node.value except KeyError: if default is _notset: @@ -1612,6 +1612,9 @@ # Walk the linked list backwards starting at tail node until we hit # a non-empty node. n = self._head.prev + + assert n is not None # help pytype + while n.key is _notset: n = n.prev