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

login
register
mail settings
Submitter phabricator
Date March 13, 2021, 7:34 p.m.
Message ID <differential-rev-PHID-DREV-j6gtpsg5zoan7qciwm6k-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48529/
State Superseded
Headers show

Comments

phabricator - March 13, 2021, 7:34 p.m.
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




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

Patch

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