44"""
55
66import re
7+ from collections import (
8+ OrderedDict ,
9+ )
710from typing import (
811 Callable ,
9- Dict ,
1012 Optional ,
1113 Union ,
1214)
@@ -173,7 +175,7 @@ def get(self, index: int) -> HistoryItem:
173175 #
174176 spanpattern = re .compile (r'^\s*(?P<start>-?[1-9]\d*)?(?P<separator>:|(\.{2,}))(?P<end>-?[1-9]\d*)?\s*$' )
175177
176- def span (self , span : str , include_persisted : bool = False ) -> Dict [int , HistoryItem ]:
178+ def span (self , span : str , include_persisted : bool = False ) -> 'OrderedDict [int, HistoryItem]' :
177179 """Return a slice of the History list
178180
179181 :param span: string containing an index or a slice
@@ -222,7 +224,7 @@ def span(self, span: str, include_persisted: bool = False) -> Dict[int, HistoryI
222224
223225 return self ._build_result_dictionary (start , end )
224226
225- def str_search (self , search : str , include_persisted : bool = False ) -> Dict [int , HistoryItem ]:
227+ def str_search (self , search : str , include_persisted : bool = False ) -> 'OrderedDict [int, HistoryItem]' :
226228 """Find history items which contain a given string
227229
228230 :param search: the string to search for
@@ -241,7 +243,7 @@ def isin(history_item: HistoryItem) -> bool:
241243 start = 0 if include_persisted else self .session_start_index
242244 return self ._build_result_dictionary (start , len (self ), isin )
243245
244- def regex_search (self , regex : str , include_persisted : bool = False ) -> Dict [int , HistoryItem ]:
246+ def regex_search (self , regex : str , include_persisted : bool = False ) -> 'OrderedDict [int, HistoryItem]' :
245247 """Find history items which match a given regular expression
246248
247249 :param regex: the regular expression to search for.
@@ -277,13 +279,13 @@ def truncate(self, max_length: int) -> None:
277279
278280 def _build_result_dictionary (
279281 self , start : int , end : int , filter_func : Optional [Callable [[HistoryItem ], bool ]] = None
280- ) -> Dict [int , HistoryItem ]:
282+ ) -> 'OrderedDict [int, HistoryItem]' :
281283 """
282284 Build history search results
283285 :param start: start index to search from
284286 :param end: end index to stop searching (exclusive)
285287 """
286- results : Dict [int , HistoryItem ] = dict ()
288+ results : OrderedDict [int , HistoryItem ] = OrderedDict ()
287289 for index in range (start , end ):
288290 if filter_func is None or filter_func (self [index ]):
289291 results [index + 1 ] = self [index ]
0 commit comments