-
Notifications
You must be signed in to change notification settings - Fork 1
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
This removes the following comments ( why? ):
|
||
except BaseException as e: | ||
output = f"\n\n{e}" | ||
new_text = output_field.text + output | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
), | ||
("class:status", " - Press "), | ||
("class:status.key", "Ctrl-C"), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,7 @@ def get_line_prefix(lineno, wrap_count): | |
if wrap_count == 0: | ||
return HTML('[%s] <style bg="orange" fg="black">--></style> ') % lineno | ||
|
||
text = str(lineno) + "-" + "*" * (lineno // 2) + ": " | ||
text = f"{str(lineno)}-" + "*" * (lineno // 2) + ": " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
return HTML('[%s.%s] <style bg="ansigreen" fg="ansiblack">%s</style>') % ( | ||
lineno, | ||
wrap_count, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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} " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
|
||
search_toolbar = SearchToolbar() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
print(HTML("\n<u>Named colors, using 16 color output.</u>")) | ||
print("(Note that it doesn't really make sense to use named colors ") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
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) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
time.sleep(sleep_time) | ||
|
||
def stop_task(label, total, sleep_time): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
time.sleep(0.01) | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
time.sleep(sleep_time) | ||
|
||
threads = [ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
time.sleep(0.01) | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
range(800), | ||
label="This is a very very very long task that requires horizontal scrolling ...", | ||
): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ | |
|
||
def main(): | ||
with ProgressBar() as pb: | ||
for i in pb(range(800)): | ||
for _ in pb(range(800)): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
time.sleep(0.01) | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
time.sleep(0.01) | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
time.sleep(1) | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
time.sleep(0.01) | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
time.sleep(1) | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
time.sleep(0.01) | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
time.sleep(0.01) | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
time.sleep(0.05) | ||
|
||
def task_2(): | ||
for i in pb(range(150)): | ||
for _ in pb(range(150)): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
time.sleep(0.08) | ||
|
||
# Start threads. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ def data(): | |
|
||
def main(): | ||
with ProgressBar() as pb: | ||
for i in pb(data()): | ||
for _ in pb(data()): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
time.sleep(0.1) | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,11 +6,12 @@ | |
This should display the prompt with all the formatting like usual, but not | ||
allow any editing. | ||
""" | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines
|
||
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 |
---|---|---|
|
@@ -68,7 +68,7 @@ def main(): | |
complete_while_typing=False, | ||
key_bindings=kb, | ||
) | ||
print("You said: %s" % text) | ||
print(f"You said: {text}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
|
||
if __name__ == "__main__": | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,7 +51,7 @@ def main(): | |
completer=animal_completer, | ||
complete_style=CompleteStyle.READLINE_LIKE, | ||
) | ||
print("You said: %s" % text) | ||
print(f"You said: {text}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
|
||
if __name__ == "__main__": | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
|
||
if __name__ == "__main__": | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
) | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
|
||
if __name__ == "__main__": | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,7 +41,7 @@ def main(): | |
else: | ||
break | ||
|
||
print("You said: %s" % text) | ||
print(f"You said: {text}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
|
||
if __name__ == "__main__": | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
b.insert_text(" ") | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
|
||
if __name__ == "__main__": | ||
|
There was a problem hiding this comment.
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:use-named-expression
)