Skip to content

Commit 95917f8

Browse files
authored
Merge pull request #7863 from asottile/py36_order_preserving_dict
py36+: remove _pytest.compat.order_preserving_dict
2 parents 13ddec9 + b6b7538 commit 95917f8

File tree

4 files changed

+9
-35
lines changed

4 files changed

+9
-35
lines changed

src/_pytest/cacheprovider.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
from _pytest import nodes
2323
from _pytest._io import TerminalWriter
2424
from _pytest.compat import final
25-
from _pytest.compat import order_preserving_dict
2625
from _pytest.config import Config
2726
from _pytest.config import ExitCode
2827
from _pytest.config.argparsing import Parser
@@ -367,8 +366,8 @@ def pytest_collection_modifyitems(
367366
yield
368367

369368
if self.active:
370-
new_items: Dict[str, nodes.Item] = order_preserving_dict()
371-
other_items: Dict[str, nodes.Item] = order_preserving_dict()
369+
new_items: Dict[str, nodes.Item] = {}
370+
other_items: Dict[str, nodes.Item] = {}
372371
for item in items:
373372
if item.nodeid not in self.cached_nodeids:
374373
new_items[item.nodeid] = item

src/_pytest/compat.py

-12
Original file line numberDiff line numberDiff line change
@@ -366,18 +366,6 @@ def __get__(self, instance, owner=None):
366366
return value
367367

368368

369-
# Sometimes an algorithm needs a dict which yields items in the order in which
370-
# they were inserted when iterated. Since Python 3.7, `dict` preserves
371-
# insertion order. Since `dict` is faster and uses less memory than
372-
# `OrderedDict`, prefer to use it if possible.
373-
if sys.version_info >= (3, 7):
374-
order_preserving_dict = dict
375-
else:
376-
from collections import OrderedDict
377-
378-
order_preserving_dict = OrderedDict
379-
380-
381369
# Perform exhaustiveness checking.
382370
#
383371
# Consider this example:

src/_pytest/fixtures.py

+5-15
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
from _pytest.compat import getlocation
4646
from _pytest.compat import is_generator
4747
from _pytest.compat import NOTSET
48-
from _pytest.compat import order_preserving_dict
4948
from _pytest.compat import safe_getattr
5049
from _pytest.config import _PluggyPlugin
5150
from _pytest.config import Config
@@ -276,21 +275,12 @@ def reorder_items(items: Sequence[nodes.Item]) -> List[nodes.Item]:
276275
item_d: Dict[_Key, Deque[nodes.Item]] = defaultdict(deque)
277276
items_by_argkey[scopenum] = item_d
278277
for item in items:
279-
# cast is a workaround for https://github.com/python/typeshed/issues/3800.
280-
keys = cast(
281-
"Dict[_Key, None]",
282-
order_preserving_dict.fromkeys(
283-
get_parametrized_fixture_keys(item, scopenum), None
284-
),
285-
)
278+
keys = dict.fromkeys(get_parametrized_fixture_keys(item, scopenum), None)
286279
if keys:
287280
d[item] = keys
288281
for key in keys:
289282
item_d[key].append(item)
290-
# cast is a workaround for https://github.com/python/typeshed/issues/3800.
291-
items_dict = cast(
292-
Dict[nodes.Item, None], order_preserving_dict.fromkeys(items, None)
293-
)
283+
items_dict = dict.fromkeys(items, None)
294284
return list(reorder_items_atscope(items_dict, argkeys_cache, items_by_argkey, 0))
295285

296286

@@ -314,17 +304,17 @@ def reorder_items_atscope(
314304
return items
315305
ignore: Set[Optional[_Key]] = set()
316306
items_deque = deque(items)
317-
items_done: Dict[nodes.Item, None] = order_preserving_dict()
307+
items_done: Dict[nodes.Item, None] = {}
318308
scoped_items_by_argkey = items_by_argkey[scopenum]
319309
scoped_argkeys_cache = argkeys_cache[scopenum]
320310
while items_deque:
321-
no_argkey_group: Dict[nodes.Item, None] = order_preserving_dict()
311+
no_argkey_group: Dict[nodes.Item, None] = {}
322312
slicing_argkey = None
323313
while items_deque:
324314
item = items_deque.popleft()
325315
if item in items_done or item in no_argkey_group:
326316
continue
327-
argkeys = order_preserving_dict.fromkeys(
317+
argkeys = dict.fromkeys(
328318
(k for k in scoped_argkeys_cache.get(item, []) if k not in ignore), None
329319
)
330320
if not argkeys:

src/_pytest/terminal.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
from _pytest._code.code import ExceptionRepr
3636
from _pytest._io.wcwidth import wcswidth
3737
from _pytest.compat import final
38-
from _pytest.compat import order_preserving_dict
3938
from _pytest.config import _PluggyPlugin
4039
from _pytest.config import Config
4140
from _pytest.config import ExitCode
@@ -909,9 +908,7 @@ def summary_warnings(self) -> None:
909908
if not warning_reports:
910909
return
911910

912-
reports_grouped_by_message: Dict[str, List[WarningReport]] = (
913-
order_preserving_dict()
914-
)
911+
reports_grouped_by_message: Dict[str, List[WarningReport]] = {}
915912
for wr in warning_reports:
916913
reports_grouped_by_message.setdefault(wr.message, []).append(wr)
917914

@@ -925,7 +922,7 @@ def collapsed_location_report(reports: List[WarningReport]) -> str:
925922
if len(locations) < 10:
926923
return "\n".join(map(str, locations))
927924

928-
counts_by_filename: Dict[str, int] = order_preserving_dict()
925+
counts_by_filename: Dict[str, int] = {}
929926
for loc in locations:
930927
key = str(loc).split("::", 1)[0]
931928
counts_by_filename[key] = counts_by_filename.get(key, 0) + 1

0 commit comments

Comments
 (0)