77values?
88"""
99
10- from templatelib import Interpolation, Template
10+ from string. templatelib import Interpolation, Template
1111
1212from .fstring import convert
1313
@@ -23,23 +23,23 @@ class Formatter:
2323 def __init__(self, template: Template):
2424 """Construct a formatter for the provided template."""
2525 # Ensure that all interpolations are strings.
26- for arg in template.args :
27- if isinstance(arg , Interpolation):
28- if not isinstance(arg .value, str):
29- raise ValueError(f"Non-string interpolation: {arg .value}")
26+ for item in template:
27+ if isinstance(item , Interpolation):
28+ if not isinstance(item .value, str):
29+ raise ValueError(f"Non-string interpolation: {item .value}")
3030 self.template = template
3131
3232 def format(self, **kwargs) -> str:
3333 """Render the t-string using the given values."""
3434 parts = []
35- for t_arg in self.template.args :
36- if isinstance(t_arg , str):
37- parts.append(t_arg )
35+ for item in self.template:
36+ if isinstance(item , str):
37+ parts.append(item )
3838 else:
39- assert isinstance(t_arg .value, str)
40- value = kwargs[t_arg .value]
41- value = convert(value, t_arg.conv )
42- value = format(value, t_arg .format_spec)
39+ assert isinstance(item .value, str)
40+ value = kwargs[item .value]
41+ value = convert(value, item.conversion )
42+ value = format(value, item .format_spec)
4343 parts.append(value)
4444 return "".join(parts)
4545
@@ -55,24 +55,24 @@ class Binder:
5555 def __init__(self, template: Template):
5656 """Construct a binder for the provided template."""
5757 # Ensure that all interpolations are strings.
58- for arg in template.args :
59- if isinstance(arg , Interpolation):
60- if not isinstance(arg .value, str):
61- raise ValueError(f"Non-string interpolation: {arg .value}")
58+ for item in template:
59+ if isinstance(item , Interpolation):
60+ if not isinstance(item .value, str):
61+ raise ValueError(f"Non-string interpolation: {item .value}")
6262 self.template = template
6363
6464 def bind(self, **kwargs) -> Template:
6565 """Bind values to the template."""
66- args = []
67- for t_arg in self.template.args :
68- if isinstance(t_arg , str):
69- args .append(t_arg )
66+ items = []
67+ for item in self.template:
68+ if isinstance(item , str):
69+ items .append(item )
7070 else:
71- assert isinstance(t_arg .value, str)
72- value = kwargs[t_arg .value]
73- expr = repr(t_arg .value)[1:-1] # remove quotes from original expression
71+ assert isinstance(item .value, str)
72+ value = kwargs[item .value]
73+ expr = repr(item .value)[1:-1] # remove quotes from original expression
7474 interpolation = Interpolation(
75- value, expr, t_arg.conv, t_arg .format_spec
75+ value, expr, item.conversion, item .format_spec
7676 )
77- args .append(interpolation)
78- return Template(*args )
77+ items .append(interpolation)
78+ return Template(*items )
0 commit comments