typing: rewrite a conditional assignment to unconfuse pytype stable
authorMatt Harbison <matt_harbison@yahoo.com>
Sat, 13 Mar 2021 02:09:23 -0500
branchstable
changeset 46421 86b47ec1960a
parent 46420 7e08fa9b3d13
child 46422 112826b59476
child 46796 e2f7b2695ba1
typing: rewrite a conditional assignment to unconfuse pytype 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]]] Differential Revision: https://phab.mercurial-scm.org/D10215
mercurial/localrepo.py
--- a/mercurial/localrepo.py	Sat Mar 13 02:07:34 2021 -0500
+++ b/mercurial/localrepo.py	Sat Mar 13 02:09:23 2021 -0500
@@ -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