Skip to content

Commit

Permalink
Merge pull request pytest-dev#7863 from asottile/py36_order_preservin…
Browse files Browse the repository at this point in the history
…g_dict

py36+: remove _pytest.compat.order_preserving_dict
  • Loading branch information
asottile committed Oct 6, 2020
2 parents 13ddec9 + b6b7538 commit 95917f8
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 35 deletions.
5 changes: 2 additions & 3 deletions src/_pytest/cacheprovider.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
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
Expand Down Expand Up @@ -367,8 +366,8 @@ def pytest_collection_modifyitems(
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
Expand Down
12 changes: 0 additions & 12 deletions src/_pytest/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,18 +366,6 @@ def __get__(self, instance, owner=None):
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:
Expand Down
20 changes: 5 additions & 15 deletions src/_pytest/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
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
Expand Down Expand Up @@ -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))


Expand All @@ -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:
Expand Down
7 changes: 2 additions & 5 deletions src/_pytest/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
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
Expand Down Expand Up @@ -909,9 +908,7 @@ def summary_warnings(self) -> None:
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)

Expand All @@ -925,7 +922,7 @@ def collapsed_location_report(reports: List[WarningReport]) -> str:
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
Expand Down

0 comments on commit 95917f8

Please sign in to comment.