##// END OF EJS Templates
templater: mark .gen as a private attribute
Yuya Nishihara -
r37293:8c84dc82 default
parent child Browse files
Show More
@@ -61,12 +61,13 b' class hybrid(wrapped):'
61
61
62 def __init__(self, gen, values, makemap, joinfmt, keytype=None):
62 def __init__(self, gen, values, makemap, joinfmt, keytype=None):
63 if gen is not None:
63 if gen is not None:
64 self.gen = gen # generator or function returning generator
64 self._gen = gen # generator or function returning generator
65 self._values = values
65 self._values = values
66 self._makemap = makemap
66 self._makemap = makemap
67 self.joinfmt = joinfmt
67 self.joinfmt = joinfmt
68 self.keytype = keytype # hint for 'x in y' where type(x) is unresolved
68 self.keytype = keytype # hint for 'x in y' where type(x) is unresolved
69 def gen(self):
69
70 def _gen(self):
70 """Default generator to stringify this as {join(self, ' ')}"""
71 """Default generator to stringify this as {join(self, ' ')}"""
71 for i, x in enumerate(self._values):
72 for i, x in enumerate(self._values):
72 if i > 0:
73 if i > 0:
@@ -79,7 +80,7 b' class hybrid(wrapped):'
79
80
80 def show(self, context, mapping):
81 def show(self, context, mapping):
81 # TODO: switch gen to (context, mapping) API?
82 # TODO: switch gen to (context, mapping) API?
82 gen = self.gen
83 gen = self._gen
83 if callable(gen):
84 if callable(gen):
84 return gen()
85 return gen()
85 return gen
86 return gen
@@ -113,12 +114,12 b' class mappable(wrapped):'
113
114
114 def __init__(self, gen, key, value, makemap):
115 def __init__(self, gen, key, value, makemap):
115 if gen is not None:
116 if gen is not None:
116 self.gen = gen # generator or function returning generator
117 self._gen = gen # generator or function returning generator
117 self._key = key
118 self._key = key
118 self._value = value # may be generator of strings
119 self._value = value # may be generator of strings
119 self._makemap = makemap
120 self._makemap = makemap
120
121
121 def gen(self):
122 def _gen(self):
122 yield pycompat.bytestr(self._value)
123 yield pycompat.bytestr(self._value)
123
124
124 def tomap(self):
125 def tomap(self):
@@ -129,7 +130,7 b' class mappable(wrapped):'
129
130
130 def show(self, context, mapping):
131 def show(self, context, mapping):
131 # TODO: switch gen to (context, mapping) API?
132 # TODO: switch gen to (context, mapping) API?
132 gen = self.gen
133 gen = self._gen
133 if callable(gen):
134 if callable(gen):
134 return gen()
135 return gen()
135 return gen
136 return gen
General Comments 0
You need to be logged in to leave comments. Login now