Mercurial > hg
comparison mercurial/templateutil.py @ 38244:688fbb758ba9
templater: resolve type of dict key in getmember()
This seems more correct and is consistent with the future wrapped.contains()
function, where a key type has to be resolved depending on a container type.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Fri, 04 May 2018 12:43:15 +0900 |
parents | 06d11cd90516 |
children | 41ae9b3cbfb9 |
comparison
equal
deleted
inserted
replaced
38243:06d11cd90516 | 38244:688fbb758ba9 |
---|---|
39 | 39 |
40 @abc.abstractmethod | 40 @abc.abstractmethod |
41 def getmember(self, context, mapping, key): | 41 def getmember(self, context, mapping, key): |
42 """Return a member item for the specified key | 42 """Return a member item for the specified key |
43 | 43 |
44 The key argument may be a wrapped object. | |
44 A returned object may be either a wrapped object or a pure value | 45 A returned object may be either a wrapped object or a pure value |
45 depending on the self type. | 46 depending on the self type. |
46 """ | 47 """ |
47 | 48 |
48 @abc.abstractmethod | 49 @abc.abstractmethod |
145 | 146 |
146 def getmember(self, context, mapping, key): | 147 def getmember(self, context, mapping, key): |
147 # TODO: maybe split hybrid list/dict types? | 148 # TODO: maybe split hybrid list/dict types? |
148 if not util.safehasattr(self._values, 'get'): | 149 if not util.safehasattr(self._values, 'get'): |
149 raise error.ParseError(_('not a dictionary')) | 150 raise error.ParseError(_('not a dictionary')) |
151 key = unwrapastype(context, mapping, key, self.keytype) | |
150 return self._wrapvalue(key, self._values.get(key)) | 152 return self._wrapvalue(key, self._values.get(key)) |
151 | 153 |
152 def _wrapvalue(self, key, val): | 154 def _wrapvalue(self, key, val): |
153 if val is None: | 155 if val is None: |
154 return | 156 return |