Skip to content

Sourcery refactored master branch #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions examples/dialogs/checkbox_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
"""
Example of a checkbox-list-based dialog.
"""

from prompt_toolkit.formatted_text import HTML
from prompt_toolkit.shortcuts import checkboxlist_dialog, message_dialog
from prompt_toolkit.styles import Style

results = checkboxlist_dialog(
if results := checkboxlist_dialog(
Comment on lines +5 to +10
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 9-30 refactored with the following changes:

title="CheckboxList dialog",
text="What would you like in your breakfast ?",
values=[
Expand All @@ -26,8 +27,7 @@
"dialog.body label": "#fd8bb6",
}
),
).run()
if results:
).run():
message_dialog(
title="Room service",
text="You selected: %s\nGreat choice sir !" % ",".join(results),
Expand Down
4 changes: 1 addition & 3 deletions examples/full-screen/calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ def main():
def accept(buff):
# Evaluate "calculator" expression.
try:
output = "\n\nIn: {}\nOut: {}".format(
input_field.text, eval(input_field.text)
) # Don't do 'eval' in real code!
output = f"\n\nIn: {input_field.text}\nOut: {eval(input_field.text)}"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function main.accept refactored with the following changes:

This removes the following comments ( why? ):

# Don't do 'eval' in real code!

except BaseException as e:
output = f"\n\n{e}"
new_text = output_field.text + output
Expand Down
7 changes: 2 additions & 5 deletions examples/full-screen/pager.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,10 @@

def get_statusbar_text():
return [
("class:status", _pager_py_path + " - "),
("class:status", f"{_pager_py_path} - "),
(
"class:status.position",
"{}:{}".format(
text_area.document.cursor_position_row + 1,
text_area.document.cursor_position_col + 1,
),
f"{text_area.document.cursor_position_row + 1}:{text_area.document.cursor_position_col + 1}",
Comment on lines -28 to +31
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_statusbar_text refactored with the following changes:

),
("class:status", " - Press "),
("class:status.key", "Ctrl-C"),
Expand Down
2 changes: 1 addition & 1 deletion examples/full-screen/simple-demos/line-prefixes.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def get_line_prefix(lineno, wrap_count):
if wrap_count == 0:
return HTML('[%s] <style bg="orange" fg="black">--&gt;</style> ') % lineno

text = str(lineno) + "-" + "*" * (lineno // 2) + ": "
text = f"{str(lineno)}-" + "*" * (lineno // 2) + ": "
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_line_prefix refactored with the following changes:

return HTML('[%s.%s] <style bg="ansigreen" fg="ansiblack">%s</style>') % (
lineno,
wrap_count,
Expand Down
5 changes: 1 addition & 4 deletions examples/full-screen/text-editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ def get_statusbar_text():


def get_statusbar_right_text():
return " {}:{} ".format(
text_field.document.cursor_position_row + 1,
text_field.document.cursor_position_col + 1,
)
return f" {text_field.document.cursor_position_row + 1}:{text_field.document.cursor_position_col + 1} "
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_statusbar_right_text refactored with the following changes:



search_toolbar = SearchToolbar()
Expand Down
2 changes: 1 addition & 1 deletion examples/print-text/named-colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


def main():
tokens = FormattedText([("fg:" + name, name + " ") for name in NAMED_COLORS])
tokens = FormattedText([(f"fg:{name}", f"{name} ") for name in NAMED_COLORS])
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function main refactored with the following changes:


print(HTML("\n<u>Named colors, using 16 color output.</u>"))
print("(Note that it doesn't really make sense to use named colors ")
Expand Down
5 changes: 1 addition & 4 deletions examples/print-text/true-color-demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ def main():
"bg:#00{0:02x}{0:02x}", # Cyan.
"bg:#{0:02x}{0:02x}{0:02x}", # Gray.
]:
fragments = []
for i in range(0, 256, 4):
fragments.append((template.format(i), " "))

fragments = [(template.format(i), " ") for i in range(0, 256, 4)]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function main refactored with the following changes:

print(FormattedText(fragments), color_depth=ColorDepth.DEPTH_4_BIT)
print(FormattedText(fragments), color_depth=ColorDepth.DEPTH_8_BIT)
print(FormattedText(fragments), color_depth=ColorDepth.DEPTH_24_BIT)
Expand Down
2 changes: 1 addition & 1 deletion examples/progress-bar/a-lot-of-parallel-tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def main():

def run_task(label, total, sleep_time):
"""Complete a normal run."""
for i in pb(range(total), label=label):
for _ in pb(range(total), label=label):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function main.run_task refactored with the following changes:

time.sleep(sleep_time)

def stop_task(label, total, sleep_time):
Expand Down
2 changes: 1 addition & 1 deletion examples/progress-bar/colored-title-and-label.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def main():
label = HTML("<ansired>some file</ansired>: ")

with ProgressBar(title=title) as pb:
for i in pb(range(800), label=label):
for _ in pb(range(800), label=label):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function main refactored with the following changes:

time.sleep(0.01)


Expand Down
2 changes: 1 addition & 1 deletion examples/progress-bar/many-parallel-tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def main():
) as pb:

def run_task(label, total, sleep_time):
for i in pb(range(total), label=label):
for _ in pb(range(total), label=label):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function main.run_task refactored with the following changes:

time.sleep(sleep_time)

threads = [
Expand Down
8 changes: 4 additions & 4 deletions examples/progress-bar/nested-progress-bars.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@

def main():
with ProgressBar(
title=HTML('<b fg="#aa00ff">Nested progress bars</b>'),
bottom_toolbar=HTML(" <b>[Control-L]</b> clear <b>[Control-C]</b> abort"),
) as pb:
title=HTML('<b fg="#aa00ff">Nested progress bars</b>'),
bottom_toolbar=HTML(" <b>[Control-L]</b> clear <b>[Control-C]</b> abort"),
) as pb:

for i in pb(range(6), label="Main task"):
for j in pb(range(200), label=f"Subtask <{i + 1}>", remove_when_done=True):
for _ in pb(range(200), label=f"Subtask <{i + 1}>", remove_when_done=True):
Comment on lines -13 to +18
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function main refactored with the following changes:

time.sleep(0.01)


Expand Down
6 changes: 3 additions & 3 deletions examples/progress-bar/scrolling-task-name.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

def main():
with ProgressBar(
title="Scrolling task name (make sure the window is not too big)."
) as pb:
for i in pb(
title="Scrolling task name (make sure the window is not too big)."
) as pb:
for _ in pb(
Comment on lines -13 to +15
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function main refactored with the following changes:

range(800),
label="This is a very very very long task that requires horizontal scrolling ...",
):
Expand Down
2 changes: 1 addition & 1 deletion examples/progress-bar/simple-progress-bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

def main():
with ProgressBar() as pb:
for i in pb(range(800)):
for _ in pb(range(800)):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function main refactored with the following changes:

time.sleep(0.01)


Expand Down
6 changes: 3 additions & 3 deletions examples/progress-bar/styled-1.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@

def main():
with ProgressBar(
style=style, title="Progress bar example with custom styling."
) as pb:
for i in pb(range(1600), label="Downloading..."):
style=style, title="Progress bar example with custom styling."
) as pb:
for _ in pb(range(1600), label="Downloading..."):
Comment on lines -29 to +31
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function main refactored with the following changes:

time.sleep(0.01)


Expand Down
10 changes: 5 additions & 5 deletions examples/progress-bar/styled-2.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ def main():
formatters.TimeLeft(),
]
with ProgressBar(
title="Progress bar example with custom formatter.",
formatters=custom_formatters,
style=style,
) as pb:
title="Progress bar example with custom formatter.",
formatters=custom_formatters,
style=style,
) as pb:

for i in pb(range(20), label="Downloading..."):
for _ in pb(range(20), label="Downloading..."):
Comment on lines -40 to +45
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function main refactored with the following changes:

time.sleep(1)


Expand Down
2 changes: 1 addition & 1 deletion examples/progress-bar/styled-apt-get-install.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def main():
]

with ProgressBar(style=style, formatters=custom_formatters) as pb:
for i in pb(range(1600), label="Installing"):
for _ in pb(range(1600), label="Installing"):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function main refactored with the following changes:

time.sleep(0.01)


Expand Down
8 changes: 2 additions & 6 deletions examples/progress-bar/styled-rainbow.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,9 @@ def main():
formatters.Rainbow(formatters.TimeLeft()),
]

if true_color:
color_depth = ColorDepth.DEPTH_24_BIT
else:
color_depth = ColorDepth.DEPTH_8_BIT

color_depth = ColorDepth.DEPTH_24_BIT if true_color else ColorDepth.DEPTH_8_BIT
with ProgressBar(formatters=custom_formatters, color_depth=color_depth) as pb:
for i in pb(range(20), label="Downloading..."):
for _ in pb(range(20), label="Downloading..."):
Comment on lines -24 to +26
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function main refactored with the following changes:

time.sleep(1)


Expand Down
2 changes: 1 addition & 1 deletion examples/progress-bar/styled-tqdm-1.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def main():
]

with ProgressBar(style=style, formatters=custom_formatters) as pb:
for i in pb(range(1600), label="Installing"):
for _ in pb(range(1600), label="Installing"):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function main refactored with the following changes:

time.sleep(0.01)


Expand Down
2 changes: 1 addition & 1 deletion examples/progress-bar/styled-tqdm-2.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def main():
]

with ProgressBar(style=style, formatters=custom_formatters) as pb:
for i in pb(range(1600), label="Installing"):
for _ in pb(range(1600), label="Installing"):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function main refactored with the following changes:

time.sleep(0.01)


Expand Down
4 changes: 2 additions & 2 deletions examples/progress-bar/two-tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ def main():
with ProgressBar() as pb:
# Two parallal tasks.
def task_1():
for i in pb(range(100)):
for _ in pb(range(100)):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function main.task_1 refactored with the following changes:

time.sleep(0.05)

def task_2():
for i in pb(range(150)):
for _ in pb(range(150)):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function main.task_2 refactored with the following changes:

time.sleep(0.08)

# Start threads.
Expand Down
2 changes: 1 addition & 1 deletion examples/progress-bar/unknown-length.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def data():

def main():
with ProgressBar() as pb:
for i in pb(data()):
for _ in pb(data()):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function main refactored with the following changes:

time.sleep(0.1)


Expand Down
3 changes: 2 additions & 1 deletion examples/prompts/accept-default.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
This should display the prompt with all the formatting like usual, but not
allow any editing.
"""

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 16-16 refactored with the following changes:

from prompt_toolkit import HTML, prompt

if __name__ == "__main__":
answer = prompt(
HTML("<b>Type <u>some input</u>: </b>"), accept_default=True, default="test"
)

print("You said: %s" % answer)
print(f"You said: {answer}")
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def main():
complete_while_typing=False,
key_bindings=kb,
)
print("You said: %s" % text)
print(f"You said: {text}")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function main refactored with the following changes:



if __name__ == "__main__":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def main():
completer=animal_completer,
complete_style=CompleteStyle.READLINE_LIKE,
)
print("You said: %s" % text)
print(f"You said: {text}")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function main refactored with the following changes:



if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion examples/prompts/auto-completion/autocompletion.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def main():
text = prompt(
"Give some animals: ", completer=animal_completer, complete_while_typing=False
)
print("You said: %s" % text)
print(f"You said: {text}")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function main refactored with the following changes:



if __name__ == "__main__":
Expand Down
4 changes: 2 additions & 2 deletions examples/prompts/auto-completion/colored-completions.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ def get_completions(self, document, complete_event):
yield Completion(
color,
start_position=-len(word),
style="fg:" + color,
selected_style="fg:white bg:" + color,
style=f"fg:{color}",
selected_style=f"fg:white bg:{color}",
Comment on lines -31 to +32
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ColorCompleter.get_completions refactored with the following changes:

)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def main():
text = prompt(
"Give some animals: ", completer=completer, complete_while_typing=False
)
print("You said: %s" % text)
print(f"You said: {text}")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function main refactored with the following changes:



if __name__ == "__main__":
Expand Down
4 changes: 2 additions & 2 deletions examples/prompts/auto-completion/fuzzy-custom-completer.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ def get_completions(self, document, complete_event):
yield Completion(
color,
start_position=-len(word),
style="fg:" + color,
selected_style="fg:white bg:" + color,
style=f"fg:{color}",
selected_style=f"fg:white bg:{color}",
)


Expand Down
2 changes: 1 addition & 1 deletion examples/prompts/auto-completion/fuzzy-word-completer.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def main():
text = prompt(
"Give some animals: ", completer=animal_completer, complete_while_typing=True
)
print("You said: %s" % text)
print(f"You said: {text}")


if __name__ == "__main__":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def main():
completer=animal_completer,
complete_style=CompleteStyle.MULTI_COLUMN,
)
print("You said: %s" % text)
print(f"You said: {text}")


if __name__ == "__main__":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def main():
completer=animal_completer,
complete_style=CompleteStyle.MULTI_COLUMN,
)
print("You said: %s" % text)
print(f"You said: {text}")


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion examples/prompts/auto-completion/nested-autocompletion.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

def main():
text = prompt("Type a command: ", completer=completer)
print("You said: %s" % text)
print(f"You said: {text}")


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion examples/prompts/auto-suggestion.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def main():
else:
break

print("You said: %s" % text)
print(f"You said: {text}")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function main refactored with the following changes:



if __name__ == "__main__":
Expand Down
7 changes: 3 additions & 4 deletions examples/prompts/autocorrection.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ def _(event):
b = event.app.current_buffer
w = b.document.get_word_before_cursor()

if w is not None:
if w in corrections:
b.delete_before_cursor(count=len(w))
b.insert_text(corrections[w])
if w is not None and w in corrections:
b.delete_before_cursor(count=len(w))
b.insert_text(corrections[w])
Comment on lines -31 to +33
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function main._ refactored with the following changes:


b.insert_text(" ")

Expand Down
2 changes: 1 addition & 1 deletion examples/prompts/clock-input.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def get_prompt():

def main():
result = prompt(get_prompt, refresh_interval=0.5)
print("You said: %s" % result)
print(f"You said: {result}")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function main refactored with the following changes:



if __name__ == "__main__":
Expand Down
Loading