Skip to content

Commit 2adc0e0

Browse files
danieleadesbranchv
authored andcommitted
lint using pyupgrade
1 parent 98e5685 commit 2adc0e0

32 files changed

+61
-80
lines changed

.pre-commit-config.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,10 @@ repos:
2323
- flake8-bugbear
2424
- flake8-comprehensions
2525
- flake8-simplify
26+
27+
- repo: https://github.com/asottile/pyupgrade
28+
rev: v2.29.1
29+
hooks:
30+
- id: pyupgrade
31+
args:
32+
- --py37-plus

cleo/_compat.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
31
import shlex
42
import subprocess
53
import sys

cleo/_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,4 @@ def format_time(secs): # type: (float) -> str
101101
if len(fmt) == 2:
102102
return fmt[1]
103103

104-
return "{} {}".format(math.ceil(secs / fmt[2]), fmt[1])
104+
return f"{math.ceil(secs / fmt[2])} {fmt[1]}"

cleo/color.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def _parse_color(self, color: str, background: bool) -> str:
109109
color = color[0] * 2 + color[1] * 2 + color[2] * 2
110110

111111
if len(color) != 6:
112-
raise ValueException('"{}" is an invalid color'.format(color))
112+
raise ValueException(f'"{color}" is an invalid color')
113113

114114
return ("4" if background else "3") + self._convert_hex_color_to_ansi(
115115
int(color, 16)
@@ -132,7 +132,7 @@ def _convert_hex_color_to_ansi(self, color: int) -> str:
132132
if os.getenv("COLORTERM") != "truecolor":
133133
return str(self._degrade_hex_color_to_ansi(r, g, b))
134134

135-
return "8;2;{};{};{}".format(r, g, b)
135+
return f"8;2;{r};{g};{b}"
136136

137137
def _degrade_hex_color_to_ansi(self, r: int, g: int, b: int) -> int:
138138
if round(self._get_saturation(r, g, b) / 50) == 0:

cleo/commands/base_command.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def __init__(self) -> None:
3636

3737
for i, usage in enumerate(self.usages):
3838
if self.name and usage.find(self.name) != 0:
39-
self.usages[i] = "{} {}".format(self.name, usage)
39+
self.usages[i] = f"{self.name} {usage}"
4040

4141
@property
4242
def application(self) -> "Application":

cleo/commands/command.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class Command(BaseCommand):
3636

3737
def __init__(self):
3838
self._io: Optional[IO] = None
39-
super(Command, self).__init__()
39+
super().__init__()
4040

4141
@property
4242
def io(self): # type: () -> IO
@@ -244,7 +244,7 @@ def write(self, text, style=None):
244244
Useful if you want to use overwrite().
245245
"""
246246
if style:
247-
styled = "<%s>%s</>" % (style, text)
247+
styled = f"<{style}>{text}</>"
248248
else:
249249
styled = text
250250

@@ -260,7 +260,7 @@ def line(
260260
Write a string as information output.
261261
"""
262262
if style:
263-
styled = "<{}>{}</>".format(style, text)
263+
styled = f"<{style}>{text}</>"
264264
else:
265265
styled = text
266266

@@ -276,7 +276,7 @@ def line_error(
276276
Write a string as information output to stderr.
277277
"""
278278
if style:
279-
styled = "<%s>%s</>" % (style, text)
279+
styled = f"<{style}>{text}</>"
280280
else:
281281
styled = text
282282

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
# -*- coding: utf-8 -*-

cleo/commands/completions/templates.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
31
BASH_TEMPLATE = """%(function)s()
42
{
53
local cur script coms opts com

cleo/commands/completions_command.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
31
import hashlib
42
import inspect
53
import os
@@ -118,7 +116,7 @@ def handle(self): # type: () -> int
118116
return 0
119117

120118
def render(self, shell): # type: (str) -> str
121-
return getattr(self, "render_{}".format(shell))()
119+
return getattr(self, f"render_{shell}")()
122120

123121
def render_bash(self): # type: () -> str
124122
template = TEMPLATES["bash"]
@@ -161,10 +159,7 @@ def render_bash(self): # type: () -> str
161159
commands_options[command.name] = command_options
162160

163161
compdefs = "\n".join(
164-
[
165-
"complete -o default -F {} {}".format(function, alias)
166-
for alias in aliases
167-
]
162+
[f"complete -o default -F {function} {alias}" for alias in aliases]
168163
)
169164

170165
commands = sorted(commands)
@@ -176,7 +171,7 @@ def render_bash(self): # type: () -> str
176171
options = [self._zsh_describe(opt, None).strip('"') for opt in options]
177172

178173
desc = [
179-
" ({})".format(command),
174+
f" ({command})",
180175
' opts="${{opts}} {}"'.format(" ".join(options)),
181176
" ;;",
182177
]
@@ -245,9 +240,7 @@ def render_zsh(self):
245240

246241
commands_options[command.name] = command_options
247242

248-
compdefs = "\n".join(
249-
["compdef {} {}".format(function, alias) for alias in aliases]
250-
)
243+
compdefs = "\n".join([f"compdef {function} {alias}" for alias in aliases])
251244

252245
commands = sorted(commands_options.keys())
253246
command_list = []
@@ -260,7 +253,7 @@ def render_zsh(self):
260253
]
261254

262255
desc = [
263-
" ({})".format(command),
256+
f" ({command})",
264257
" opts+=({})".format(" ".join(options)),
265258
" ;;",
266259
]
@@ -359,7 +352,7 @@ def render_fish(self):
359352
)
360353
)
361354

362-
cmds_opts += ["# {}".format(cmd)]
355+
cmds_opts += [f"# {cmd}"]
363356
options = set(commands_options[cmd]).difference(global_options)
364357
options = sorted(options)
365358

cleo/cursor.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,32 +21,32 @@ def __init__(self, io: Union[IO, Output], input: Optional[TextIO] = None) -> Non
2121
self._input = input
2222

2323
def move_up(self, lines: int = 1) -> "Cursor":
24-
self._output.write("\x1b[{}A".format(lines))
24+
self._output.write(f"\x1b[{lines}A")
2525

2626
return self
2727

2828
def move_down(self, lines: int = 1) -> "Cursor":
29-
self._output.write("\x1b[{}B".format(lines))
29+
self._output.write(f"\x1b[{lines}B")
3030

3131
return self
3232

3333
def move_right(self, columns: int = 1) -> "Cursor":
34-
self._output.write("\x1b[{}C".format(columns))
34+
self._output.write(f"\x1b[{columns}C")
3535

3636
return self
3737

3838
def move_left(self, columns: int = 1) -> "Cursor":
39-
self._output.write("\x1b[{}D".format(columns))
39+
self._output.write(f"\x1b[{columns}D")
4040

4141
return self
4242

4343
def move_to_column(self, column: int) -> "Cursor":
44-
self._output.write("\x1b[{}G".format(column))
44+
self._output.write(f"\x1b[{column}G")
4545

4646
return self
4747

4848
def move_to_position(self, column: int, row: int) -> "Cursor":
49-
self._output.write("\x1b[{};{}H".format(row + 1, column))
49+
self._output.write(f"\x1b[{row + 1};{column}H")
5050

5151
return self
5252

0 commit comments

Comments
 (0)