Mercurial > public > mercurial-scm > hg
comparison mercurial/util.py @ 51295:c8a2fdf5ca37
pytype: add the couple annotations for pytype to understands the lrunode
After loosing 2d6 SAN, I eventually understood that pytype was confused by method
return type. Pytype is now happy.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Thu, 21 Dec 2023 00:19:19 +0100 |
parents | 7d3b92e8df13 |
children | 187c5769a629 |
comparison
equal
deleted
inserted
replaced
51294:4d12ffde8377 | 51295:c8a2fdf5ca37 |
---|---|
1525 except KeyError: | 1525 except KeyError: |
1526 if default is _notset: | 1526 if default is _notset: |
1527 raise | 1527 raise |
1528 return default | 1528 return default |
1529 | 1529 |
1530 assert node is not None # help pytype | |
1531 value = node.value | 1530 value = node.value |
1532 self.totalcost -= node.cost | 1531 self.totalcost -= node.cost |
1533 node.markempty() | 1532 node.markempty() |
1534 | 1533 |
1535 # Temporarily mark as newest item before re-adjusting head to make | 1534 # Temporarily mark as newest item before re-adjusting head to make |
1553 Unlike get(), this doesn't mutate the internal state. But be aware | 1552 Unlike get(), this doesn't mutate the internal state. But be aware |
1554 that it doesn't mean peek() is thread safe. | 1553 that it doesn't mean peek() is thread safe. |
1555 """ | 1554 """ |
1556 try: | 1555 try: |
1557 node = self._cache[k] | 1556 node = self._cache[k] |
1558 assert node is not None # help pytype | |
1559 return node.value | 1557 return node.value |
1560 except KeyError: | 1558 except KeyError: |
1561 if default is _notset: | 1559 if default is _notset: |
1562 raise | 1560 raise |
1563 return default | 1561 return default |
1612 | 1610 |
1613 # Walk the linked list backwards starting at tail node until we hit | 1611 # Walk the linked list backwards starting at tail node until we hit |
1614 # a non-empty node. | 1612 # a non-empty node. |
1615 n = self._head.prev | 1613 n = self._head.prev |
1616 | 1614 |
1617 assert n is not None # help pytype | |
1618 | |
1619 while n.key is _notset: | 1615 while n.key is _notset: |
1620 n = n.prev | 1616 n = n.prev |
1621 | |
1622 assert n is not None # help pytype | |
1623 | 1617 |
1624 key, value = n.key, n.value | 1618 key, value = n.key, n.value |
1625 | 1619 |
1626 # And remove it from the cache and mark it as empty. | 1620 # And remove it from the cache and mark it as empty. |
1627 del self._cache[n.key] | 1621 del self._cache[n.key] |
1628 self.totalcost -= n.cost | 1622 self.totalcost -= n.cost |
1629 n.markempty() | 1623 n.markempty() |
1630 | 1624 |
1631 return key, value | 1625 return key, value |
1632 | 1626 |
1633 def _movetohead(self, node): | 1627 def _movetohead(self, node: _lrucachenode): |
1634 """Mark a node as the newest, making it the new head. | 1628 """Mark a node as the newest, making it the new head. |
1635 | 1629 |
1636 When a node is accessed, it becomes the freshest entry in the LRU | 1630 When a node is accessed, it becomes the freshest entry in the LRU |
1637 list, which is denoted by self._head. | 1631 list, which is denoted by self._head. |
1638 | 1632 |
1675 # A.prev = N | 1669 # A.prev = N |
1676 node.prev.next = node | 1670 node.prev.next = node |
1677 | 1671 |
1678 self._head = node | 1672 self._head = node |
1679 | 1673 |
1680 def _addcapacity(self): | 1674 def _addcapacity(self) -> _lrucachenode: |
1681 """Add a node to the circular linked list. | 1675 """Add a node to the circular linked list. |
1682 | 1676 |
1683 The new node is inserted before the head node. | 1677 The new node is inserted before the head node. |
1684 """ | 1678 """ |
1685 head = self._head | 1679 head = self._head |