py36+: remove _pytest.compat.order_preserving_dict

This commit is contained in:
Anthony Sottile 2020-10-05 18:30:40 -07:00
parent f54ec30a6d
commit b6b75383ce
4 changed files with 9 additions and 35 deletions

View File

@ -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

View File

@ -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:

View File

@ -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:

View File

@ -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