Skip to content

Commit e15c209

Browse files
committed
Automated refactoring to replace ancient print % formatting with f-strings amd the like
1 parent c9fa34d commit e15c209

19 files changed

+46
-52
lines changed

cmd2/history.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ class to gain access to the historical record.
165165
_history_items_field = 'history_items'
166166

167167
def __init__(self, seq: Iterable[HistoryItem] = ()) -> None:
168-
super(History, self).__init__(seq)
168+
super().__init__(seq)
169169
self.session_start_index = 0
170170

171171
def start_session(self) -> None:
@@ -192,7 +192,7 @@ def append(self, new: Union[Statement, HistoryItem]) -> None:
192192
and added to the end of the list
193193
"""
194194
history_item = HistoryItem(new) if isinstance(new, Statement) else new
195-
super(History, self).append(history_item)
195+
super().append(history_item)
196196

197197
def clear(self) -> None:
198198
"""Remove all items from the History list."""

examples/cmd_as_argument.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def do_speak(self, args):
4949
words = []
5050
for word in args.words:
5151
if args.piglatin:
52-
word = '%s%say' % (word[1:], word[0])
52+
word = f'{word[1:]}{word[0]}ay'
5353
if args.shout:
5454
word = word.upper()
5555
words.append(word)

examples/colors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def do_speak(self, args):
6363
words = []
6464
for word in args.words:
6565
if args.piglatin:
66-
word = '%s%say' % (word[1:], word[0])
66+
word = f'{word[1:]}{word[0]}ay'
6767
if args.shout:
6868
word = word.upper()
6969
words.append(word)

examples/decorator_example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def do_speak(self, args: argparse.Namespace):
4646
words = []
4747
for word in args.words:
4848
if args.piglatin:
49-
word = '%s%say' % (word[1:], word[0])
49+
word = f'{word[1:]}{word[0]}ay'
5050
if args.shout:
5151
word = word.upper()
5252
words.append(word)

examples/default_categories.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class ExampleApp(cmd2.Cmd):
7575
"""
7676

7777
def __init__(self):
78-
super(ExampleApp, self).__init__()
78+
super().__init__()
7979

8080
def do_something(self, arg):
8181
self.poutput('this is the something command')

examples/example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def do_speak(self, args):
4545
words = []
4646
for word in args.words:
4747
if args.piglatin:
48-
word = '%s%say' % (word[1:], word[0])
48+
word = f'{word[1:]}{word[0]}ay'
4949
if args.shout:
5050
word = word.upper()
5151
words.append(word)

examples/first_app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def do_speak(self, args):
3939
words = []
4040
for word in args.words:
4141
if args.piglatin:
42-
word = '%s%say' % (word[1:], word[0])
42+
word = f'{word[1:]}{word[0]}ay'
4343
if args.shout:
4444
word = word.upper()
4545
words.append(word)

examples/modular_commands_basic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class ExampleApp(cmd2.Cmd):
2828
"""
2929

3030
def __init__(self):
31-
super(ExampleApp, self).__init__()
31+
super().__init__()
3232

3333
def do_something(self, arg):
3434
self.poutput('this is the something command')

examples/subcommands.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def base_foo(self, args):
7777

7878
def base_bar(self, args):
7979
"""bar subcommand of base command"""
80-
self.poutput('((%s))' % args.z)
80+
self.poutput(f'(({args.z}))')
8181

8282
def base_sport(self, args):
8383
"""sport subcommand of base command"""

tests/test_argparse.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def do_say(self, args, *, keyword_arg: Optional[str] = None):
4747
if word is None:
4848
word = ''
4949
if args.piglatin:
50-
word = '%s%say' % (word[1:], word[0])
50+
word = f'{word[1:]}{word[0]}ay'
5151
if args.shout:
5252
word = word.upper()
5353
words.append(word)
@@ -102,7 +102,7 @@ def do_speak(self, args, extra, *, keyword_arg: Optional[str] = None):
102102
if word is None:
103103
word = ''
104104
if args.piglatin:
105-
word = '%s%say' % (word[1:], word[0])
105+
word = f'{word[1:]}{word[0]}ay'
106106
if args.shout:
107107
word = word.upper()
108108
words.append(word)
@@ -266,11 +266,11 @@ def base_foo(self, args):
266266

267267
def base_bar(self, args):
268268
"""bar subcommand of base command"""
269-
self.poutput('((%s))' % args.z)
269+
self.poutput(f'(({args.z}))')
270270

271271
def base_helpless(self, args):
272272
"""helpless subcommand of base command"""
273-
self.poutput('((%s))' % args.z)
273+
self.poutput(f'(({args.z}))')
274274

275275
# create the top-level parser for the base command
276276
base_parser = cmd2.Cmd2ArgumentParser()

0 commit comments

Comments
 (0)