comparison mercurial/templateutil.py @ 38268:49ef1539b84e

templater: mark .keytype as a private attribute
author Yuya Nishihara <yuya@tcha.org>
date Fri, 23 Mar 2018 22:31:58 +0900
parents fb874fc1d9b4
children cf8d210dfac4
comparison
equal deleted inserted replaced
38267:fb874fc1d9b4 38268:49ef1539b84e
181 def __init__(self, gen, values, makemap, joinfmt, keytype=None): 181 def __init__(self, gen, values, makemap, joinfmt, keytype=None):
182 self._gen = gen # generator or function returning generator 182 self._gen = gen # generator or function returning generator
183 self._values = values 183 self._values = values
184 self._makemap = makemap 184 self._makemap = makemap
185 self._joinfmt = joinfmt 185 self._joinfmt = joinfmt
186 self.keytype = keytype # hint for 'x in y' where type(x) is unresolved 186 self._keytype = keytype # hint for 'x in y' where type(x) is unresolved
187 187
188 def contains(self, context, mapping, item): 188 def contains(self, context, mapping, item):
189 item = unwrapastype(context, mapping, item, self.keytype) 189 item = unwrapastype(context, mapping, item, self._keytype)
190 return item in self._values 190 return item in self._values
191 191
192 def getmember(self, context, mapping, key): 192 def getmember(self, context, mapping, key):
193 # TODO: maybe split hybrid list/dict types? 193 # TODO: maybe split hybrid list/dict types?
194 if not util.safehasattr(self._values, 'get'): 194 if not util.safehasattr(self._values, 'get'):
195 raise error.ParseError(_('not a dictionary')) 195 raise error.ParseError(_('not a dictionary'))
196 key = unwrapastype(context, mapping, key, self.keytype) 196 key = unwrapastype(context, mapping, key, self._keytype)
197 return self._wrapvalue(key, self._values.get(key)) 197 return self._wrapvalue(key, self._values.get(key))
198 198
199 def getmin(self, context, mapping): 199 def getmin(self, context, mapping):
200 return self._getby(context, mapping, min) 200 return self._getby(context, mapping, min)
201 201