Mercurial > hg
comparison mercurial/templateutil.py @ 40935:4591c9791a82
templatefuncs: specialize "no match" value of search() to allow % operation
If Python had Maybe or Option, the type of the search() result would be
Option<Mapping>, which can be considered as a 0/1 container of a Mapping.
So it makes sense that {search(r'no match pattern', x) % "whatever"} is
mapped to an empty string.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Wed, 12 Dec 2018 22:45:02 +0900 |
parents | 8fa26f3baf30 |
children | 832c59d1196e |
comparison
equal
deleted
inserted
replaced
40934:d3e688b9ef2e | 40935:4591c9791a82 |
---|---|
492 # mark this as non-empty. | 492 # mark this as non-empty. |
493 return True | 493 return True |
494 | 494 |
495 def tovalue(self, context, mapping): | 495 def tovalue(self, context, mapping): |
496 return super(mappingdict, self).tovalue(context, mapping)[0] | 496 return super(mappingdict, self).tovalue(context, mapping)[0] |
497 | |
498 class mappingnone(wrappedvalue): | |
499 """Wrapper for None, but supports map operation | |
500 | |
501 This represents None of Optional[mappable]. It's similar to | |
502 mapplinglist([]), but the underlying value is not [], but None. | |
503 """ | |
504 | |
505 def __init__(self): | |
506 super(mappingnone, self).__init__(None) | |
507 | |
508 def itermaps(self, context): | |
509 return iter([]) | |
497 | 510 |
498 class mappedgenerator(wrapped): | 511 class mappedgenerator(wrapped): |
499 """Wrapper for generator of strings which acts as a list | 512 """Wrapper for generator of strings which acts as a list |
500 | 513 |
501 The function ``make(context, *args)`` should return a generator of | 514 The function ``make(context, *args)`` should return a generator of |