Patchwork D10276: typing: make minor adjustments to mercurial/util.py to pass pytype checking

login
register
mail settings
Submitter phabricator
Date March 26, 2021, 4:40 a.m.
Message ID <differential-rev-PHID-DREV-h7auahgvhzauu6i3z5rg-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48591/
State Superseded
Headers show

Comments

phabricator - March 26, 2021, 4:40 a.m.
mharbison72 created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  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.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D10276

AFFECTED FILES
  mercurial/util.py
  tests/test-check-pytype.t

CHANGE DETAILS




To: mharbison72, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/tests/test-check-pytype.t b/tests/test-check-pytype.t
--- a/tests/test-check-pytype.t
+++ b/tests/test-check-pytype.t
@@ -89,7 +89,6 @@ 
   >    -x mercurial/ui.py \
   >    -x mercurial/unionrepo.py \
   >    -x mercurial/upgrade.py \
-  >    -x mercurial/util.py \
   >    -x mercurial/utils/procutil.py \
   >    -x mercurial/utils/stringutil.py \
   >    -x mercurial/utils/memorytop.py \
diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -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