Mercurial > public > mercurial-scm > hg-stable
diff mercurial/templater.py @ 39598:28f974d83c0a
templater: remove unused context argument from most resourcemapper functions
While working on demand loading of ctx/fctx objects, I noticed that it's quite
easy to create infinite recursion by carelessly using the template context in
the resource mapper. Let's make that not happen.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Thu, 07 Jun 2018 23:27:54 +0900 |
parents | 3813c6b7337c |
children | 8fa26f3baf30 |
line wrap: on
line diff
--- a/mercurial/templater.py Mon Sep 10 20:57:18 2018 +0900 +++ b/mercurial/templater.py Thu Jun 07 23:27:54 2018 +0900 @@ -548,7 +548,7 @@ __metaclass__ = abc.ABCMeta @abc.abstractmethod - def availablekeys(self, context, mapping): + def availablekeys(self, mapping): """Return a set of available resource keys based on the given mapping""" @abc.abstractmethod @@ -556,7 +556,7 @@ """Return a set of supported resource keys""" @abc.abstractmethod - def lookup(self, context, mapping, key): + def lookup(self, mapping, key): """Return a resource for the key if available; otherwise None""" @abc.abstractmethod @@ -565,13 +565,13 @@ with the given new mapping""" class nullresourcemapper(resourcemapper): - def availablekeys(self, context, mapping): + def availablekeys(self, mapping): return set() def knownkeys(self): return set() - def lookup(self, context, mapping, key): + def lookup(self, mapping, key): return None def populatemap(self, context, origmapping, newmapping): @@ -618,7 +618,7 @@ # do not copy symbols which overrides the defaults depending on # new resources, so the defaults will be re-evaluated (issue5612) knownres = self._resources.knownkeys() - newres = self._resources.availablekeys(self, newmapping) + newres = self._resources.availablekeys(newmapping) mapping = {k: v for k, v in origmapping.iteritems() if (k in knownres # not a symbol per self.symbol() or newres.isdisjoint(self._defaultrequires(k)))} @@ -645,7 +645,7 @@ def availableresourcekeys(self, mapping): """Return a set of available resource keys based on the given mapping""" - return self._resources.availablekeys(self, mapping) + return self._resources.availablekeys(mapping) def knownresourcekeys(self): """Return a set of supported resource keys""" @@ -654,7 +654,7 @@ def resource(self, mapping, key): """Return internal data (e.g. cache) used for keyword/function evaluation""" - v = self._resources.lookup(self, mapping, key) + v = self._resources.lookup(mapping, key) if v is None: raise templateutil.ResourceUnavailable( _('template resource not available: %s') % key)