D10214: typing: add assertions to localrepo.py to appease pytype

mharbison72 (Matt Harbison) phabricator at mercurial-scm.org
Sat Mar 13 19:34:40 UTC 2021


mharbison72 created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REPOSITORY
  rHG Mercurial

BRANCH
  stable

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

AFFECTED FILES
  mercurial/localrepo.py

CHANGE DETAILS

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -2303,6 +2303,7 @@
 
             def tracktags(tr2):
                 repo = reporef()
+                assert repo is not None  # help pytype
                 oldfnodes = tagsmod.fnoderevs(repo.ui, repo, oldheads)
                 newheads = repo.changelog.headrevs()
                 newfnodes = tagsmod.fnoderevs(repo.ui, repo, newheads)
@@ -2339,6 +2340,7 @@
             # gating.
             tracktags(tr2)
             repo = reporef()
+            assert repo is not None  # help pytype
 
             singleheadopt = (b'experimental', b'single-head-per-branch')
             singlehead = repo.ui.configbool(*singleheadopt)
@@ -2442,6 +2444,8 @@
 
             def hookfunc(unused_success):
                 repo = reporef()
+                assert repo is not None  # help pytype
+
                 if hook.hashook(repo.ui, b'txnclose-bookmark'):
                     bmchanges = sorted(tr.changes[b'bookmarks'].items())
                     for name, (old, new) in bmchanges:
@@ -2473,7 +2477,9 @@
                     b'txnclose', throw=False, **pycompat.strkwargs(hookargs)
                 )
 
-            reporef()._afterlock(hookfunc)
+            repo = reporef()
+            assert repo is not None  # help pytype
+            repo._afterlock(hookfunc)
 
         tr.addfinalize(b'txnclose-hook', txnclosehook)
         # Include a leading "-" to make it happen before the transaction summary
@@ -2484,7 +2490,9 @@
 
         def txnaborthook(tr2):
             """To be run if transaction is aborted"""
-            reporef().hook(
+            repo = reporef()
+            assert repo is not None  # help pytype
+            repo.hook(
                 b'txnabort', throw=False, **pycompat.strkwargs(tr2.hookargs)
             )
 
@@ -2667,6 +2675,7 @@
 
         def updater(tr):
             repo = reporef()
+            assert repo is not None  # help pytype
             repo.updatecaches(tr)
 
         return updater



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


More information about the Mercurial-devel mailing list