10
10
import datetime
11
11
import os
12
12
import time
13
+ import warnings
13
14
from abc import ABCMeta , abstractmethod
14
15
from threading import Thread
15
16
from typing import Callable , Iterable , List , Optional
16
- import warnings
17
17
18
18
__all__ = [
19
19
"History" ,
@@ -40,7 +40,10 @@ def __init__(self) -> None:
40
40
# Methods expected by `Buffer`.
41
41
#
42
42
43
- def load (self , item_loaded_callback : Callable [[str ], None ],) -> None :
43
+ def load (
44
+ self ,
45
+ item_loaded_callback : Callable [[str ], None ],
46
+ ) -> None :
44
47
"""
45
48
Load the history and call the callback for every entry in the history.
46
49
This one assumes the callback is only called from same thread as `Buffer` is using.
@@ -103,13 +106,13 @@ class ThreadedHistory(History):
103
106
"""
104
107
105
108
def __init__ (
106
- self , history : History , event_loop : asyncio .BaseEventLoop = None
109
+ self , history : History , event_loop : Optional [ asyncio .AbstractEventLoop ] = None
107
110
) -> None :
108
111
"""Create instance of ThreadedHistory
109
112
110
113
Args:
111
114
history (History): Instance of History intended to run on a background thread.
112
- event_loop (asyncio.BaseEventLoop , optional): The event loop on which prompt toolkit is running.
115
+ event_loop (asyncio.AbstractEventLoop , optional): The event loop on which prompt toolkit is running.
113
116
(Deprecated) Defaults to ``asyncio.get_event_loop(), which may *create* the event loop. Caller should provide an explicit value.
114
117
"""
115
118
self .history = history
@@ -151,7 +154,10 @@ def call_all_callbacks(item: str) -> None:
151
154
self ._load_thread .daemon = True
152
155
self ._load_thread .start ()
153
156
154
- def bg_loader (self , item_loaded_callback : Callable [[str ], None ],) -> None :
157
+ def bg_loader (
158
+ self ,
159
+ item_loaded_callback : Callable [[str ], None ],
160
+ ) -> None :
155
161
"""
156
162
Load the history and schedule the callback for every entry in the history.
157
163
TODO: extend the callback so it can take a batch of lines in one event_loop dispatch.
0 commit comments