Patchwork D10215: typing: rewrite a conditional assignment to unconfuse pytype

login
register
mail settings
Submitter phabricator
Date March 13, 2021, 7:34 p.m.
Message ID <differential-rev-PHID-DREV-l4sbor7dzcfjcukq64uz-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48530/
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.

REVISION SUMMARY
  Otherwise, pytype and PyCharm flags it:
  
    File "/mnt/c/Users/Matt/hg/mercurial/localrepo.py", line 2903, in wlock: No attribute 'held' on _weakref.ReferenceType[nothing] [attribute-error]
      In Optional[Union[Any, _weakref.ReferenceType[nothing]]]
    File "/mnt/c/Users/Matt/hg/mercurial/localrepo.py", line 2904, in wlock: No attribute 'lock' on _weakref.ReferenceType[nothing] [attribute-error]
      In Optional[Union[Any, _weakref.ReferenceType[nothing]]]

REPOSITORY
  rHG Mercurial

BRANCH
  stable

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

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
@@ -2891,7 +2891,7 @@ 
 
         If both 'lock' and 'wlock' must be acquired, ensure you always acquires
         'wlock' first to avoid a dead-lock hazard."""
-        l = self._wlockref and self._wlockref()
+        l = self._wlockref() if self._wlockref else None
         if l is not None and l.held:
             l.lock()
             return l