From b6b75383ceae9184e82fe6df884459f99ecaba9b Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Mon, 5 Oct 2020 18:30:40 -0700 Subject: [PATCH] py36+: remove _pytest.compat.order_preserving_dict --- src/_pytest/cacheprovider.py | 5 ++--- src/_pytest/compat.py | 12 ------------ src/_pytest/fixtures.py | 20 +++++--------------- src/_pytest/terminal.py | 7 ++----- 4 files changed, 9 insertions(+), 35 deletions(-) diff --git a/src/_pytest/cacheprovider.py b/src/_pytest/cacheprovider.py index 9d548880e..2c8128f61 100755 --- a/src/_pytest/cacheprovider.py +++ b/src/_pytest/cacheprovider.py @@ -22,7 +22,6 @@ from .reports import CollectReport from _pytest import nodes from _pytest._io import TerminalWriter from _pytest.compat import final -from _pytest.compat import order_preserving_dict from _pytest.config import Config from _pytest.config import ExitCode from _pytest.config.argparsing import Parser @@ -367,8 +366,8 @@ class NFPlugin: yield if self.active: - new_items: Dict[str, nodes.Item] = order_preserving_dict() - other_items: Dict[str, nodes.Item] = order_preserving_dict() + new_items: Dict[str, nodes.Item] = {} + other_items: Dict[str, nodes.Item] = {} for item in items: if item.nodeid not in self.cached_nodeids: new_items[item.nodeid] = item diff --git a/src/_pytest/compat.py b/src/_pytest/compat.py index f704a990e..0b6b1ca07 100644 --- a/src/_pytest/compat.py +++ b/src/_pytest/compat.py @@ -366,18 +366,6 @@ else: return value -# Sometimes an algorithm needs a dict which yields items in the order in which -# they were inserted when iterated. Since Python 3.7, `dict` preserves -# insertion order. Since `dict` is faster and uses less memory than -# `OrderedDict`, prefer to use it if possible. -if sys.version_info >= (3, 7): - order_preserving_dict = dict -else: - from collections import OrderedDict - - order_preserving_dict = OrderedDict - - # Perform exhaustiveness checking. # # Consider this example: diff --git a/src/_pytest/fixtures.py b/src/_pytest/fixtures.py index f00f534d8..cd114456d 100644 --- a/src/_pytest/fixtures.py +++ b/src/_pytest/fixtures.py @@ -45,7 +45,6 @@ from _pytest.compat import getimfunc from _pytest.compat import getlocation from _pytest.compat import is_generator from _pytest.compat import NOTSET -from _pytest.compat import order_preserving_dict from _pytest.compat import safe_getattr from _pytest.config import _PluggyPlugin from _pytest.config import Config @@ -276,21 +275,12 @@ def reorder_items(items: Sequence[nodes.Item]) -> List[nodes.Item]: item_d: Dict[_Key, Deque[nodes.Item]] = defaultdict(deque) items_by_argkey[scopenum] = item_d for item in items: - # cast is a workaround for https://github.com/python/typeshed/issues/3800. - keys = cast( - "Dict[_Key, None]", - order_preserving_dict.fromkeys( - get_parametrized_fixture_keys(item, scopenum), None - ), - ) + keys = dict.fromkeys(get_parametrized_fixture_keys(item, scopenum), None) if keys: d[item] = keys for key in keys: item_d[key].append(item) - # cast is a workaround for https://github.com/python/typeshed/issues/3800. - items_dict = cast( - Dict[nodes.Item, None], order_preserving_dict.fromkeys(items, None) - ) + items_dict = dict.fromkeys(items, None) return list(reorder_items_atscope(items_dict, argkeys_cache, items_by_argkey, 0)) @@ -314,17 +304,17 @@ def reorder_items_atscope( return items ignore: Set[Optional[_Key]] = set() items_deque = deque(items) - items_done: Dict[nodes.Item, None] = order_preserving_dict() + items_done: Dict[nodes.Item, None] = {} scoped_items_by_argkey = items_by_argkey[scopenum] scoped_argkeys_cache = argkeys_cache[scopenum] while items_deque: - no_argkey_group: Dict[nodes.Item, None] = order_preserving_dict() + no_argkey_group: Dict[nodes.Item, None] = {} slicing_argkey = None while items_deque: item = items_deque.popleft() if item in items_done or item in no_argkey_group: continue - argkeys = order_preserving_dict.fromkeys( + argkeys = dict.fromkeys( (k for k in scoped_argkeys_cache.get(item, []) if k not in ignore), None ) if not argkeys: diff --git a/src/_pytest/terminal.py b/src/_pytest/terminal.py index a5eaeb382..0e8db20c7 100644 --- a/src/_pytest/terminal.py +++ b/src/_pytest/terminal.py @@ -35,7 +35,6 @@ from _pytest._code import ExceptionInfo from _pytest._code.code import ExceptionRepr from _pytest._io.wcwidth import wcswidth from _pytest.compat import final -from _pytest.compat import order_preserving_dict from _pytest.config import _PluggyPlugin from _pytest.config import Config from _pytest.config import ExitCode @@ -909,9 +908,7 @@ class TerminalReporter: if not warning_reports: return - reports_grouped_by_message: Dict[str, List[WarningReport]] = ( - order_preserving_dict() - ) + reports_grouped_by_message: Dict[str, List[WarningReport]] = {} for wr in warning_reports: reports_grouped_by_message.setdefault(wr.message, []).append(wr) @@ -925,7 +922,7 @@ class TerminalReporter: if len(locations) < 10: return "\n".join(map(str, locations)) - counts_by_filename: Dict[str, int] = order_preserving_dict() + counts_by_filename: Dict[str, int] = {} for loc in locations: key = str(loc).split("::", 1)[0] counts_by_filename[key] = counts_by_filename.get(key, 0) + 1