Skip to content

Commit fe087fe

Browse files
committed
Replace format with f-strings.
1 parent 38c065b commit fe087fe

File tree

9 files changed

+19
-19
lines changed

9 files changed

+19
-19
lines changed

sqlparse/cli.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,15 @@ def create_parser():
6060
dest='keyword_case',
6161
choices=_CASE_CHOICES,
6262
help='change case of keywords, CHOICE is one of {}'.format(
63-
', '.join('"{}"'.format(x) for x in _CASE_CHOICES)))
63+
', '.join(f'"{x}"' for x in _CASE_CHOICES)))
6464

6565
group.add_argument(
6666
'-i', '--identifiers',
6767
metavar='CHOICE',
6868
dest='identifier_case',
6969
choices=_CASE_CHOICES,
7070
help='change case of identifiers, CHOICE is one of {}'.format(
71-
', '.join('"{}"'.format(x) for x in _CASE_CHOICES)))
71+
', '.join(f'"{x}"' for x in _CASE_CHOICES)))
7272

7373
group.add_argument(
7474
'-l', '--language',
@@ -157,7 +157,7 @@ def create_parser():
157157

158158
def _error(msg):
159159
"""Print msg and optionally exit with return code exit_."""
160-
sys.stderr.write('[ERROR] {}\n'.format(msg))
160+
sys.stderr.write(f'[ERROR] {msg}\n')
161161
return 1
162162

163163

@@ -177,23 +177,23 @@ def main(args=None):
177177
data = ''.join(f.readlines())
178178
except OSError as e:
179179
return _error(
180-
'Failed to read {}: {}'.format(args.filename, e))
180+
f'Failed to read {args.filename}: {e}')
181181

182182
close_stream = False
183183
if args.outfile:
184184
try:
185185
stream = open(args.outfile, 'w', encoding=args.encoding)
186186
close_stream = True
187187
except OSError as e:
188-
return _error('Failed to open {}: {}'.format(args.outfile, e))
188+
return _error(f'Failed to open {args.outfile}: {e}')
189189
else:
190190
stream = sys.stdout
191191

192192
formatter_opts = vars(args)
193193
try:
194194
formatter_opts = sqlparse.formatter.validate_options(formatter_opts)
195195
except SQLParseError as e:
196-
return _error('Invalid options: {}'.format(e))
196+
return _error(f'Invalid options: {e}')
197197

198198
s = sqlparse.format(data, **formatter_opts)
199199
stream.write(s)

sqlparse/filters/aligned_indent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def _process_default(self, tlist):
126126
self._process(sgroup)
127127

128128
def _process(self, tlist):
129-
func_name = '_process_{cls}'.format(cls=type(tlist).__name__)
129+
func_name = f'_process_{type(tlist).__name__}'
130130
func = getattr(self, func_name.lower(), self._process_default)
131131
func(tlist)
132132

sqlparse/filters/others.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def process(self, stmt):
8181

8282
class StripWhitespaceFilter:
8383
def _stripws(self, tlist):
84-
func_name = '_stripws_{cls}'.format(cls=type(tlist).__name__)
84+
func_name = f'_stripws_{type(tlist).__name__}'
8585
func = getattr(self, func_name.lower(), self._stripws_default)
8686
func(tlist)
8787

sqlparse/filters/reindent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def _split_statements(self, tlist):
9797
tidx, token = tlist.token_next_by(t=ttypes, idx=tidx)
9898

9999
def _process(self, tlist):
100-
func_name = '_process_{cls}'.format(cls=type(tlist).__name__)
100+
func_name = f'_process_{type(tlist).__name__}'
101101
func = getattr(self, func_name.lower(), self._process_default)
102102
func(tlist)
103103

sqlparse/filters/right_margin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def _process(self, group, stream):
3737
indent = match.group()
3838
else:
3939
indent = ''
40-
yield sql.Token(T.Whitespace, '\n{}'.format(indent))
40+
yield sql.Token(T.Whitespace, f'\n{indent}')
4141
self.line = indent
4242
self.line += val
4343
yield token

sqlparse/sql.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@ def _pprint_tree(self, max_depth=None, depth=0, f=None, _pre=''):
189189
pre = '`- ' if last else '|- '
190190

191191
q = '"' if value.startswith("'") and value.endswith("'") else "'"
192-
print("{_pre}{pre}{idx} {cls} {q}{value}{q}"
193-
.format(**locals()), file=f)
192+
print(f"{_pre}{pre}{idx} {cls} {q}{value}{q}"
193+
, file=f)
194194

195195
if token.is_group and (max_depth is None or depth < max_depth):
196196
parent_pre = ' ' if last else '| '

tests/test_grouping.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ def test_comparison_with_parenthesis():
506506
))
507507
def test_comparison_with_strings(operator):
508508
# issue148
509-
p = sqlparse.parse("foo {} 'bar'".format(operator))[0]
509+
p = sqlparse.parse(f"foo {operator} 'bar'")[0]
510510
assert len(p.tokens) == 1
511511
assert isinstance(p.tokens[0], sql.Comparison)
512512
assert p.tokens[0].right.value == "'bar'"
@@ -585,7 +585,7 @@ def test_comparison_with_typed_literal():
585585

586586
@pytest.mark.parametrize('start', ['FOR', 'FOREACH'])
587587
def test_forloops(start):
588-
p = sqlparse.parse('{} foo in bar LOOP foobar END LOOP'.format(start))[0]
588+
p = sqlparse.parse(f'{start} foo in bar LOOP foobar END LOOP')[0]
589589
assert (len(p.tokens)) == 1
590590
assert isinstance(p.tokens[0], sql.For)
591591

tests/test_regressions.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,9 @@ def test_parse_sql_with_binary():
159159
# See https://github.com/andialbrecht/sqlparse/pull/88
160160
# digest = '‚|ËêŠplL4¡h‘øN{'
161161
digest = '\x82|\xcb\x0e\xea\x8aplL4\xa1h\x91\xf8N{'
162-
sql = "select * from foo where bar = '{}'".format(digest)
162+
sql = f"select * from foo where bar = '{digest}'"
163163
formatted = sqlparse.format(sql, reindent=True)
164-
tformatted = "select *\nfrom foo\nwhere bar = '{}'".format(digest)
164+
tformatted = f"select *\nfrom foo\nwhere bar = '{digest}'"
165165
assert formatted == tformatted
166166

167167

@@ -336,9 +336,9 @@ def test_issue315_utf8_by_default():
336336
'\x9b\xb2.'
337337
'\xec\x82\xac\xeb\x9e\x91\xed\x95\xb4\xec\x9a\x94'
338338
)
339-
sql = "select * from foo where bar = '{}'".format(digest)
339+
sql = f"select * from foo where bar = '{digest}'"
340340
formatted = sqlparse.format(sql, reindent=True)
341-
tformatted = "select *\nfrom foo\nwhere bar = '{}'".format(digest)
341+
tformatted = f"select *\nfrom foo\nwhere bar = '{digest}'"
342342
assert formatted == tformatted
343343

344344

tests/test_tokenize.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def test_stream_error():
150150
'INNER JOIN',
151151
'LEFT INNER JOIN'])
152152
def test_parse_join(expr):
153-
p = sqlparse.parse('{} foo'.format(expr))[0]
153+
p = sqlparse.parse(f'{expr} foo')[0]
154154
assert len(p.tokens) == 3
155155
assert p.tokens[0].ttype is T.Keyword
156156

0 commit comments

Comments
 (0)