Skip to content

Commit 8a947dc

Browse files
committed
More syntax nits from CI.
1 parent c51fa9b commit 8a947dc

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

examples/prompts/history/bug_thread_history.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55
Seems to happen with very large history being loaded and causing slowdowns.
66
77
"""
8+
import re
89
import time
910

1011
from prompt_toolkit import PromptSession
1112
from prompt_toolkit.history import History, ThreadedHistory
1213

13-
import re
14-
1514

1615
class MegaHistory(History):
1716
"""
@@ -20,36 +19,40 @@ class MegaHistory(History):
2019
Sample designed to exercise existing multitasking hazards, don't add any more.
2120
"""
2221

23-
def __init__(self, init_request:int = 1000, *args, **kwargs):
22+
def __init__(self, init_request: int = 1000, *args, **kwargs):
2423
super(MegaHistory, self).__init__(*args, **kwargs)
25-
self.requested_count = 0 # only modified by main (requesting) thread
26-
self.requested_commands = 0 # only modified by main (requesting) thread
27-
self.actual_count = 0 # only modified by background thread
24+
self.requested_count = 0 # only modified by main (requesting) thread
25+
self.requested_commands = 0 # only modified by main (requesting) thread
26+
self.actual_count = 0 # only modified by background thread
2827

2928
def load_history_strings(self):
3029
while True:
3130
while self.requested_count <= self.actual_count:
32-
time.sleep(0.001) # don't busy loop
31+
time.sleep(0.001) # don't busy loop
3332

34-
print(f'... starting to load {self.requested_count - self.actual_count:15,d} more items.')
33+
print(
34+
f"... starting to load {self.requested_count - self.actual_count:15,d} more items."
35+
)
3536
while self.requested_count > self.actual_count:
3637
yield f"History item {self.actual_count:15,d}, command number {self.requested_commands}"
3738
self.actual_count += 1
38-
print('...done.')
39+
print("...done.")
3940

4041
def store_string(self, string):
4142
pass # Don't store strings.
4243

4344
# called by main thread, watch out for multitasking hazards.
44-
def add_request(self, requested:int = 0):
45+
def add_request(self, requested: int = 0):
4546
self.requested_count += requested
4647
self.requested_commands += 1
4748

4849
def show_request(self):
49-
print(f'Have loaded {self.actual_count:15,d} of {self.requested_count:15,d} in {self.requested_commands} commands.')
50+
print(
51+
f"Have loaded {self.actual_count:15,d} of {self.requested_count:15,d} in {self.requested_commands} commands."
52+
)
5053

5154

52-
HIST_CMD = re.compile(r'^hist (load (\d+)|show)$', re.IGNORECASE)
55+
HIST_CMD = re.compile(r"^hist (load (\d+)|show)$", re.IGNORECASE)
5356

5457

5558
def main():
@@ -73,17 +76,17 @@ def main():
7376

7477
while True:
7578
text = session.prompt("Say something: ")
76-
if text.startswith('hist'):
79+
if text.startswith("hist"):
7780
m = HIST_CMD.match(text)
7881
if not m:
79-
print('eh?')
82+
print("eh?")
8083
else:
81-
if m[1] == 'show':
84+
if m[1] == "show":
8285
mh.show_request()
83-
elif m[1].startswith('load'):
86+
elif m[1].startswith("load"):
8487
mh.add_request(int(m[2]))
8588
else:
86-
print('eh? hist load nnnnnn\nor hist show')
89+
print("eh? hist load nnnnnn\nor hist show")
8790
pass
8891
else:
8992
print("You said: %s" % text)

prompt_toolkit/history.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
when a history entry is loaded. This loading can be done asynchronously
77
and making the history swappable would probably break this.
88
"""
9+
import asyncio
910
import datetime
1011
import os
12+
import time
1113
from abc import ABCMeta, abstractmethod
1214
from threading import Thread
1315
from typing import Callable, Iterable, List, Optional
14-
import asyncio
15-
import time
1616

1717
__all__ = [
1818
"History",
@@ -39,11 +39,7 @@ def __init__(self) -> None:
3939
# Methods expected by `Buffer`.
4040
#
4141

42-
def load(
43-
self,
44-
item_loaded_callback: Callable[[str], None],
45-
event_loop: asyncio.BaseEventLoop = None,
46-
) -> None:
42+
def load(self, item_loaded_callback: Callable[[str], None],) -> None:
4743
"""
4844
Load the history and call the callback for every entry in the history.
4945
This one assumes the callback is only called from same thread as `Buffer` is using.
@@ -112,6 +108,7 @@ def __init__(self, history: History) -> None:
112108
super().__init__()
113109

114110
def load(self, item_loaded_callback: Callable[[str], None]) -> None:
111+
115112
"""Collect the history strings on a background thread,
116113
but run the callback in the event loop.
117114

0 commit comments

Comments
 (0)