Mercurial > evolve
diff hgext3rd/topic/topicmap.py @ 6795:1b59ddda3242 stable
topic: further "help pytype" by not mentioning remotebranchcache on hg 4.9
Because it doesn't exist.
This obviously was a real issue on Mercurial 4.9 because we were trying to
directly reference a class that doesn't exist in branchmap module, it wasn't a
string in some typing comment or whatever, so this code previously would not
work on 4.9 at all. Oops!
author | Anton Shestakov <av6@dwimlabs.net> |
---|---|
date | Thu, 27 Jun 2024 17:14:50 +0400 |
parents | 68f7ba35ea83 |
children | ed00ed185249 |
line wrap: on
line diff
--- a/hgext3rd/topic/topicmap.py Thu Jun 27 16:59:29 2024 +0400 +++ b/hgext3rd/topic/topicmap.py Thu Jun 27 17:14:50 2024 +0400 @@ -180,6 +180,12 @@ else: oldbranchmap = util.nullcontextmanager +if util.safehasattr(branchmap, 'branchcache'): + allbccls = (branchmap.branchcache,) + if util.safehasattr(branchmap, 'remotebranchcache'): + # hg <= 4.9 (eb7ce452e0fb) + allbccls = (branchmap.branchcache, branchmap.remotebranchcache) + class _topiccache(object): # combine me with branchmap.branchcache def __init__(self, *args, **kwargs): @@ -189,7 +195,7 @@ def copy(self): """return an deep copy of the branchcache object""" - assert isinstance(self, (branchmap.branchcache, branchmap.remotebranchcache)) # help pytype + assert isinstance(self, allbccls) # help pytype entries = compat.bcentries(self) args = (entries, self.tipnode, self.tiprev, self.filteredhash, self._closednodes) @@ -218,7 +224,7 @@ - False when cached tipnode is unknown or if we detect a strip. - True when cache is up to date or a subset of current repo.""" - assert isinstance(self, (branchmap.branchcache, branchmap.remotebranchcache)) # help pytype + assert isinstance(self, allbccls) # help pytype valid = super(_topiccache, self).validfor(repo) if not valid: return False @@ -255,7 +261,7 @@ missing heads, and a generator of nodes that are strictly a superset of heads missing, this function updates self to be correct. """ - assert isinstance(self, (branchmap.branchcache, branchmap.remotebranchcache)) # help pytype + assert isinstance(self, allbccls) # help pytype if not istopicfilter(repo.filtername): return super(_topiccache, self).update(repo, revgen)