Skip to content

Commit 380644a

Browse files
Upgrade to 3.6 syntax using pyupgrade.
1 parent 0980bc3 commit 380644a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+166
-199
lines changed

docs/conf.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
#
32
# prompt_toolkit documentation build configuration file, created by
43
# sphinx-quickstart on Thu Jul 31 14:17:08 2014.

examples/dialogs/button_dialog.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def main():
1212
buttons=[("Yes", True), ("No", False), ("Maybe...", None)],
1313
).run()
1414

15-
print("Result = {}".format(result))
15+
print(f"Result = {result}")
1616

1717

1818
if __name__ == "__main__":

examples/dialogs/input_dialog.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def main():
1010
title="Input dialog example", text="Please type your name:"
1111
).run()
1212

13-
print("Result = {}".format(result))
13+
print(f"Result = {result}")
1414

1515

1616
if __name__ == "__main__":

examples/dialogs/password_dialog.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def main():
1212
password=True,
1313
).run()
1414

15-
print("Result = {}".format(result))
15+
print(f"Result = {result}")
1616

1717

1818
if __name__ == "__main__":

examples/dialogs/progress_dialog.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def worker(set_percentage, log_text):
1919
percentage = 0
2020
for dirpath, dirnames, filenames in os.walk("../.."):
2121
for f in filenames:
22-
log_text("{} / {}\n".format(dirpath, f))
22+
log_text(f"{dirpath} / {f}\n")
2323
set_percentage(percentage + 1)
2424
percentage += 2
2525
time.sleep(0.1)

examples/dialogs/radio_dialog.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def main():
1818
text="Please select a color:",
1919
).run()
2020

21-
print("Result = {}".format(result))
21+
print(f"Result = {result}")
2222

2323
# With HTML.
2424
result = radiolist_dialog(
@@ -32,7 +32,7 @@ def main():
3232
text="Please select a color:",
3333
).run()
3434

35-
print("Result = {}".format(result))
35+
print(f"Result = {result}")
3636

3737

3838
if __name__ == "__main__":

examples/dialogs/yes_no_dialog.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def main():
1010
title="Yes/No dialog example", text="Do you want to confirm?"
1111
).run()
1212

13-
print("Result = {}".format(result))
13+
print(f"Result = {result}")
1414

1515

1616
if __name__ == "__main__":

examples/full-screen/ansi-art-and-textarea.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env python
2-
from __future__ import unicode_literals
32

43
from prompt_toolkit.application import Application
54
from prompt_toolkit.formatted_text import ANSI, HTML

examples/full-screen/calculator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def accept(buff):
5454
input_field.text, eval(input_field.text)
5555
) # Don't do 'eval' in real code!
5656
except BaseException as e:
57-
output = "\n\n{}".format(e)
57+
output = f"\n\n{e}"
5858
new_text = output_field.text + output
5959

6060
# Add text to output buffer.

examples/full-screen/text-editor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,8 @@ async def coroutine():
185185
try:
186186
with open(path, "rb") as f:
187187
text_field.text = f.read().decode("utf-8", errors="ignore")
188-
except IOError as e:
189-
show_message("Error", "{}".format(e))
188+
except OSError as e:
189+
show_message("Error", f"{e}")
190190

191191
ensure_future(coroutine())
192192

examples/progress-bar/nested-progress-bars.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ def main():
1515
) as pb:
1616

1717
for i in pb(range(6), label="Main task"):
18-
for j in pb(
19-
range(200), label="Subtask <%s>" % (i + 1,), remove_when_done=True
20-
):
18+
for j in pb(range(200), label=f"Subtask <{i + 1}>", remove_when_done=True):
2119
time.sleep(0.01)
2220

2321

examples/progress-bar/unknown-length.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ def data():
1313
A generator that produces items. len() doesn't work here, so the progress
1414
bar can't estimate the time it will take.
1515
"""
16-
for i in range(1000):
17-
yield i
16+
yield from range(1000)
1817

1918

2019
def main():

examples/prompts/asyncio-prompt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ async def interactive_shell():
4545
while True:
4646
try:
4747
result = await session.prompt_async()
48-
print('You said: "{0}"'.format(result))
48+
print(f'You said: "{result}"')
4949
except (EOFError, KeyboardInterrupt):
5050
return
5151

examples/prompts/clock-input.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def get_prompt():
1111
"Tokens to be shown before the prompt."
1212
now = datetime.datetime.now()
1313
return [
14-
("bg:#008800 #ffffff", "%s:%s:%s" % (now.hour, now.minute, now.second)),
14+
("bg:#008800 #ffffff", f"{now.hour}:{now.minute}:{now.second}"),
1515
("bg:cornsilk fg:maroon", " Enter something: "),
1616
]
1717

examples/prompts/finalterm-shell-integration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def get_prompt_text():
3535
# Option 2: Using ANSI escape sequences.
3636
before = "\001" + BEFORE_PROMPT + "\002"
3737
after = "\001" + AFTER_PROMPT + "\002"
38-
answer = prompt(ANSI("{}Say something: # {}".format(before, after)))
38+
answer = prompt(ANSI(f"{before}Say something: # {after}"))
3939

4040
# Output.
4141
sys.stdout.write(BEFORE_OUTPUT)

examples/prompts/history/slow-history.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class SlowHistory(History):
1919
def load_history_strings(self):
2020
for i in range(1000):
2121
time.sleep(1) # Emulate slowness.
22-
yield "item-%s" % (i,)
22+
yield f"item-{i}"
2323

2424
def store_string(self, string):
2525
pass # Don't store strings.

examples/telnet/dialog.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ async def interact(connection):
1818
title="Yes/no dialog demo", text="Press yes or no"
1919
).run_async()
2020

21-
connection.send("You said: {}\n".format(result))
21+
connection.send(f"You said: {result}\n")
2222
connection.send("Bye.\n")
2323

2424

examples/telnet/hello-world.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ async def interact(connection):
2525
result = await prompt(message="Say something: ", async_=True)
2626

2727
# Send output.
28-
connection.send("You said: {}\n".format(result))
28+
connection.send(f"You said: {result}\n")
2929
connection.send("Bye.\n")
3030

3131

examples/telnet/toolbar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def get_toolbar():
3131
"Say something: ", bottom_toolbar=get_toolbar, completer=animal_completer
3232
)
3333

34-
connection.send("You said: {}\n".format(result))
34+
connection.send(f"You said: {result}\n")
3535
connection.send("Bye.\n")
3636

3737

prompt_toolkit/application/application.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -583,8 +583,7 @@ def _update_invalidate_events(self) -> None:
583583
# (All controls are able to invalidate themselves.)
584584
def gather_events() -> Iterable[Event[object]]:
585585
for c in self.layout.find_all_controls():
586-
for ev in c.get_invalidate_events():
587-
yield ev
586+
yield from c.get_invalidate_events()
588587

589588
self._invalidate_events = list(gather_events())
590589

@@ -959,7 +958,7 @@ async def in_term() -> None:
959958
# but don't use logger. (This works better on Python 2.)
960959
print("\nUnhandled exception in event loop:")
961960
print(formatted_tb)
962-
print("Exception %s" % (context.get("exception"),))
961+
print("Exception {}".format(context.get("exception")))
963962

964963
await _do_wait_for_enter("Press ENTER to continue...")
965964

@@ -1256,10 +1255,8 @@ def get_used_style_strings(self) -> List[str]:
12561255

12571256
if attrs_for_style:
12581257
return sorted(
1259-
[
1260-
re.sub(r"\s+", " ", style_str).strip()
1261-
for style_str in attrs_for_style.keys()
1262-
]
1258+
re.sub(r"\s+", " ", style_str).strip()
1259+
for style_str in attrs_for_style.keys()
12631260
)
12641261

12651262
return []

prompt_toolkit/application/current.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def __init__(
5353
self.app: Optional["Application[Any]"] = None
5454

5555
def __repr__(self) -> str:
56-
return "AppSession(app=%r)" % (self.app,)
56+
return f"AppSession(app={self.app!r})"
5757

5858
@property
5959
def input(self) -> "Input":

prompt_toolkit/buffer.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def __init__(
9595
self.complete_index = complete_index # Position in the `_completions` array.
9696

9797
def __repr__(self) -> str:
98-
return "%s(%r, <%r> completions, index=%r)" % (
98+
return "{}({!r}, <{!r}> completions, index={!r})".format(
9999
self.__class__.__name__,
100100
self.original_document,
101101
len(self.completions),
@@ -160,7 +160,7 @@ def __init__(
160160
self.n = n
161161

162162
def __repr__(self) -> str:
163-
return "%s(history_position=%r, n=%r, previous_inserted_word=%r)" % (
163+
return "{}(history_position={!r}, n={!r}, previous_inserted_word={!r})".format(
164164
self.__class__.__name__,
165165
self.history_position,
166166
self.n,
@@ -317,7 +317,7 @@ def __repr__(self) -> str:
317317
else:
318318
text = self.text[:12] + "..."
319319

320-
return "<Buffer(name=%r, text=%r) at %r>" % (self.name, text, id(self))
320+
return f"<Buffer(name={self.name!r}, text={text!r}) at {id(self)!r}>"
321321

322322
def reset(
323323
self, document: Optional[Document] = None, append_to_history: bool = False
@@ -967,7 +967,7 @@ def start_history_lines_completion(self) -> None:
967967
if i == self.working_index:
968968
display_meta = "Current, line %s" % (j + 1)
969969
else:
970-
display_meta = "History %s, line %s" % (i + 1, j + 1)
970+
display_meta = f"History {i + 1}, line {j + 1}"
971971

972972
completions.append(
973973
Completion(

prompt_toolkit/completion/base.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ def __init__(
6565

6666
def __repr__(self) -> str:
6767
if isinstance(self.display, str) and self.display == self.text:
68-
return "%s(text=%r, start_position=%r)" % (
68+
return "{}(text={!r}, start_position={!r})".format(
6969
self.__class__.__name__,
7070
self.text,
7171
self.start_position,
7272
)
7373
else:
74-
return "%s(text=%r, start_position=%r, display=%r)" % (
74+
return "{}(text={!r}, start_position={!r}, display={!r})".format(
7575
self.__class__.__name__,
7676
self.text,
7777
self.start_position,
@@ -155,7 +155,7 @@ def __init__(
155155
self.completion_requested = completion_requested
156156

157157
def __repr__(self) -> str:
158-
return "%s(text_inserted=%r, completion_requested=%r)" % (
158+
return "{}(text_inserted={!r}, completion_requested={!r})".format(
159159
self.__class__.__name__,
160160
self.text_inserted,
161161
self.completion_requested,
@@ -230,7 +230,7 @@ async def get_completions_async(
230230
yield completion
231231

232232
def __repr__(self) -> str:
233-
return "ThreadedCompleter(%r)" % (self.completer,)
233+
return f"ThreadedCompleter({self.completer!r})"
234234

235235

236236
class DummyCompleter(Completer):
@@ -274,7 +274,7 @@ async def get_completions_async(
274274
yield completion
275275

276276
def __repr__(self) -> str:
277-
return "DynamicCompleter(%r -> %r)" % (self.get_completer, self.get_completer())
277+
return f"DynamicCompleter({self.get_completer!r} -> {self.get_completer()!r})"
278278

279279

280280
class ConditionalCompleter(Completer):
@@ -291,15 +291,14 @@ def __init__(self, completer: Completer, filter: FilterOrBool) -> None:
291291
self.filter = to_filter(filter)
292292

293293
def __repr__(self) -> str:
294-
return "ConditionalCompleter(%r, filter=%r)" % (self.completer, self.filter)
294+
return f"ConditionalCompleter({self.completer!r}, filter={self.filter!r})"
295295

296296
def get_completions(
297297
self, document: Document, complete_event: CompleteEvent
298298
) -> Iterable[Completion]:
299299
# Get all completions in a blocking way.
300300
if self.filter():
301-
for c in self.completer.get_completions(document, complete_event):
302-
yield c
301+
yield from self.completer.get_completions(document, complete_event)
303302

304303
async def get_completions_async(
305304
self, document: Document, complete_event: CompleteEvent
@@ -326,8 +325,7 @@ def get_completions(
326325
) -> Iterable[Completion]:
327326
# Get all completions from the other completers in a blocking way.
328327
for completer in self.completers:
329-
for c in completer.get_completions(document, complete_event):
330-
yield c
328+
yield from completer.get_completions(document, complete_event)
331329

332330
async def get_completions_async(
333331
self, document: Document, complete_event: CompleteEvent

prompt_toolkit/completion/fuzzy_completer.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def _get_fuzzy_completions(
9393
fuzzy_matches: List[_FuzzyMatch] = []
9494

9595
pat = ".*?".join(map(re.escape, word_before_cursor))
96-
pat = "(?=({0}))".format(pat) # lookahead regex to manage overlapping matches
96+
pat = f"(?=({pat}))" # lookahead regex to manage overlapping matches
9797
regex = re.compile(pat, re.IGNORECASE)
9898
for compl in completions:
9999
matches = list(regex.finditer(compl.text))
@@ -195,7 +195,7 @@ def get_completions(
195195
return self.fuzzy_completer.get_completions(document, complete_event)
196196

197197

198-
_FuzzyMatch = NamedTuple(
199-
"_FuzzyMatch",
200-
[("match_length", int), ("start_pos", int), ("completion", Completion)],
201-
)
198+
class _FuzzyMatch(NamedTuple):
199+
match_length: int
200+
start_pos: int
201+
completion: Completion

prompt_toolkit/completion/nested.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def __init__(
3333
self.ignore_case = ignore_case
3434

3535
def __repr__(self) -> str:
36-
return "NestedCompleter(%r, ignore_case=%r)" % (self.options, self.ignore_case)
36+
return f"NestedCompleter({self.options!r}, ignore_case={self.ignore_case!r})"
3737

3838
@classmethod
3939
def from_nested_dict(cls, data: NestedDict) -> "NestedCompleter":
@@ -97,13 +97,11 @@ def get_completions(
9797
cursor_position=document.cursor_position - move_cursor,
9898
)
9999

100-
for c in completer.get_completions(new_document, complete_event):
101-
yield c
100+
yield from completer.get_completions(new_document, complete_event)
102101

103102
# No space in the input: behave exactly like `WordCompleter`.
104103
else:
105104
completer = WordCompleter(
106105
list(self.options.keys()), ignore_case=self.ignore_case
107106
)
108-
for c in completer.get_completions(document, complete_event):
109-
yield c
107+
yield from completer.get_completions(document, complete_event)

0 commit comments

Comments
 (0)