Skip to content

Commit

Permalink
faster render_attrs
Browse files Browse the repository at this point in the history
  • Loading branch information
Hrabal committed Mar 31, 2019
1 parent e50bae7 commit de29f0f
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions tempy/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ def render_attrs(self):
ret = []
for k, v in self.attrs.items():
if v:
f_string = (' %s="%s"', " %s")[v is bool]
f_args = (
self._SPECIAL_ATTRS.get(k, k),
self._FORMAT_ATTRS.get(k, lambda x: x)(v),
)[: 2 - (v is bool)]
ret.append(f_string % f_args)
if v is bool:
ret.append(" %s" % self._SPECIAL_ATTRS.get(k, k))
else:
fnc = self._FORMAT_ATTRS.get(k, None)
val = fnc(v) if fnc else v
ret.append(' %s="%s"' % (self._SPECIAL_ATTRS.get(k, k), val))
return "".join(ret)

def to_code_attrs(self):
Expand Down

0 comments on commit de29f0f

Please sign in to comment.