Patchwork D10236: commands: necessary annotations and assertions to pass pytype

login
register
mail settings
Submitter phabricator
Date March 19, 2021, 5:59 a.m.
Message ID <differential-rev-PHID-DREV-vn3ntabnjvlggpo7byi4-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48553/
State Superseded
Headers show

Comments

phabricator - March 19, 2021, 5:59 a.m.
mharbison72 created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This is a slightly less forceful incarnation of D7384 <https://phab.mercurial-scm.org/D7384>, where pytype can be
  appeased with some assertions rather than disabling warnings.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/commands.py

CHANGE DETAILS




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

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -76,6 +76,12 @@ 
     stringutil,
 )
 
+if pycompat.TYPE_CHECKING:
+    from typing import (
+        List,
+    )
+
+
 table = {}
 table.update(debugcommandsmod.command._table)
 
@@ -3295,7 +3301,8 @@ 
                 )
             # checking that newnodes exist because old state files won't have it
             elif statedata.get(b'newnodes') is not None:
-                statedata[b'newnodes'].append(node)
+                nn = statedata[b'newnodes']  # type: List[bytes]
+                nn.append(node)
 
     # remove state when we complete successfully
     if not opts.get(b'dry_run'):
@@ -7268,6 +7275,12 @@ 
         dest = dbranch = dother = outgoing = None
 
     if opts.get(b'remote'):
+        # Help pytype.  --remote sets both `needsincoming` and `needsoutgoing`.
+        # The former always sets `sother` (or raises an exception if it can't);
+        # the latter always sets `outgoing`.
+        assert sother is not None
+        assert outgoing is not None
+
         t = []
         if incoming:
             t.append(_(b'1 or more incoming'))