Skip to content

Commit 2d79945

Browse files
committed
Removed use of OrderedDict.
1 parent 910f2eb commit 2d79945

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

cmd2/cmd2.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,7 @@
4141
import tempfile
4242
import threading
4343
from code import InteractiveConsole
44-
from collections import (
45-
OrderedDict,
46-
namedtuple,
47-
)
44+
from collections import namedtuple
4845
from collections.abc import (
4946
Callable,
5047
Iterable,
@@ -4961,15 +4958,15 @@ def do_history(self, args: argparse.Namespace) -> bool | None:
49614958
self.last_result = history
49624959
return None
49634960

4964-
def _get_history(self, args: argparse.Namespace) -> 'OrderedDict[int, HistoryItem]':
4961+
def _get_history(self, args: argparse.Namespace) -> dict[int, HistoryItem]:
49654962
"""If an argument was supplied, then retrieve partial contents of the history; otherwise retrieve entire history.
49664963
49674964
This function returns a dictionary with history items keyed by their 1-based index in ascending order.
49684965
"""
49694966
if args.arg:
49704967
try:
49714968
int_arg = int(args.arg)
4972-
return OrderedDict({int_arg: self.history.get(int_arg)})
4969+
return {int_arg: self.history.get(int_arg)}
49734970
except ValueError:
49744971
pass
49754972

cmd2/history.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import json
44
import re
5-
from collections import OrderedDict
65
from collections.abc import (
76
Callable,
87
Iterable,
@@ -224,7 +223,7 @@ def get(self, index: int) -> HistoryItem:
224223
#
225224
spanpattern = re.compile(r'^\s*(?P<start>-?[1-9]\d*)?(?P<separator>:|(\.{2,}))(?P<end>-?[1-9]\d*)?\s*$')
226225

227-
def span(self, span: str, include_persisted: bool = False) -> 'OrderedDict[int, HistoryItem]':
226+
def span(self, span: str, include_persisted: bool = False) -> dict[int, 'HistoryItem']:
228227
"""Return a slice of the History list.
229228
230229
:param span: string containing an index or a slice
@@ -273,7 +272,7 @@ def span(self, span: str, include_persisted: bool = False) -> 'OrderedDict[int,
273272

274273
return self._build_result_dictionary(start, end)
275274

276-
def str_search(self, search: str, include_persisted: bool = False) -> 'OrderedDict[int, HistoryItem]':
275+
def str_search(self, search: str, include_persisted: bool = False) -> dict[int, 'HistoryItem']:
277276
"""Find history items which contain a given string.
278277
279278
:param search: the string to search for
@@ -292,7 +291,7 @@ def isin(history_item: HistoryItem) -> bool:
292291
start = 0 if include_persisted else self.session_start_index
293292
return self._build_result_dictionary(start, len(self), isin)
294293

295-
def regex_search(self, regex: str, include_persisted: bool = False) -> 'OrderedDict[int, HistoryItem]':
294+
def regex_search(self, regex: str, include_persisted: bool = False) -> dict[int, 'HistoryItem']:
296295
"""Find history items which match a given regular expression.
297296
298297
:param regex: the regular expression to search for.
@@ -328,13 +327,13 @@ def truncate(self, max_length: int) -> None:
328327

329328
def _build_result_dictionary(
330329
self, start: int, end: int, filter_func: Callable[[HistoryItem], bool] | None = None
331-
) -> 'OrderedDict[int, HistoryItem]':
330+
) -> dict[int, 'HistoryItem']:
332331
"""Build history search results.
333332
334333
:param start: start index to search from
335334
:param end: end index to stop searching (exclusive).
336335
"""
337-
results: OrderedDict[int, HistoryItem] = OrderedDict()
336+
results: dict[int, HistoryItem] = {}
338337
for index in range(start, end):
339338
if filter_func is None or filter_func(self[index]):
340339
results[index + 1] = self[index]

0 commit comments

Comments
 (0)