# HG changeset patch # User Anton Shestakov # Date 1719494090 -14400 # Node ID 1b59ddda32427e38bc5eea835b092e2fab26b62c # Parent 68f7ba35ea83e3196aa87458b34b38dd803e5b9c 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! diff -r 68f7ba35ea83 -r 1b59ddda3242 hgext3rd/topic/topicmap.py --- 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)