Merge pull request #7863 from asottile/py36_order_preserving_dict
py36+: remove _pytest.compat.order_preserving_dict
This commit is contained in:
commit
95917f8833
|
@ -22,7 +22,6 @@ from .reports import CollectReport
|
||||||
from _pytest import nodes
|
from _pytest import nodes
|
||||||
from _pytest._io import TerminalWriter
|
from _pytest._io import TerminalWriter
|
||||||
from _pytest.compat import final
|
from _pytest.compat import final
|
||||||
from _pytest.compat import order_preserving_dict
|
|
||||||
from _pytest.config import Config
|
from _pytest.config import Config
|
||||||
from _pytest.config import ExitCode
|
from _pytest.config import ExitCode
|
||||||
from _pytest.config.argparsing import Parser
|
from _pytest.config.argparsing import Parser
|
||||||
|
@ -367,8 +366,8 @@ class NFPlugin:
|
||||||
yield
|
yield
|
||||||
|
|
||||||
if self.active:
|
if self.active:
|
||||||
new_items: Dict[str, nodes.Item] = order_preserving_dict()
|
new_items: Dict[str, nodes.Item] = {}
|
||||||
other_items: Dict[str, nodes.Item] = order_preserving_dict()
|
other_items: Dict[str, nodes.Item] = {}
|
||||||
for item in items:
|
for item in items:
|
||||||
if item.nodeid not in self.cached_nodeids:
|
if item.nodeid not in self.cached_nodeids:
|
||||||
new_items[item.nodeid] = item
|
new_items[item.nodeid] = item
|
||||||
|
|
|
@ -366,18 +366,6 @@ else:
|
||||||
return value
|
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.
|
# Perform exhaustiveness checking.
|
||||||
#
|
#
|
||||||
# Consider this example:
|
# Consider this example:
|
||||||
|
|
|
@ -45,7 +45,6 @@ from _pytest.compat import getimfunc
|
||||||
from _pytest.compat import getlocation
|
from _pytest.compat import getlocation
|
||||||
from _pytest.compat import is_generator
|
from _pytest.compat import is_generator
|
||||||
from _pytest.compat import NOTSET
|
from _pytest.compat import NOTSET
|
||||||
from _pytest.compat import order_preserving_dict
|
|
||||||
from _pytest.compat import safe_getattr
|
from _pytest.compat import safe_getattr
|
||||||
from _pytest.config import _PluggyPlugin
|
from _pytest.config import _PluggyPlugin
|
||||||
from _pytest.config import Config
|
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)
|
item_d: Dict[_Key, Deque[nodes.Item]] = defaultdict(deque)
|
||||||
items_by_argkey[scopenum] = item_d
|
items_by_argkey[scopenum] = item_d
|
||||||
for item in items:
|
for item in items:
|
||||||
# cast is a workaround for https://github.com/python/typeshed/issues/3800.
|
keys = dict.fromkeys(get_parametrized_fixture_keys(item, scopenum), None)
|
||||||
keys = cast(
|
|
||||||
"Dict[_Key, None]",
|
|
||||||
order_preserving_dict.fromkeys(
|
|
||||||
get_parametrized_fixture_keys(item, scopenum), None
|
|
||||||
),
|
|
||||||
)
|
|
||||||
if keys:
|
if keys:
|
||||||
d[item] = keys
|
d[item] = keys
|
||||||
for key in keys:
|
for key in keys:
|
||||||
item_d[key].append(item)
|
item_d[key].append(item)
|
||||||
# cast is a workaround for https://github.com/python/typeshed/issues/3800.
|
items_dict = dict.fromkeys(items, None)
|
||||||
items_dict = cast(
|
|
||||||
Dict[nodes.Item, None], order_preserving_dict.fromkeys(items, None)
|
|
||||||
)
|
|
||||||
return list(reorder_items_atscope(items_dict, argkeys_cache, items_by_argkey, 0))
|
return list(reorder_items_atscope(items_dict, argkeys_cache, items_by_argkey, 0))
|
||||||
|
|
||||||
|
|
||||||
|
@ -314,17 +304,17 @@ def reorder_items_atscope(
|
||||||
return items
|
return items
|
||||||
ignore: Set[Optional[_Key]] = set()
|
ignore: Set[Optional[_Key]] = set()
|
||||||
items_deque = deque(items)
|
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_items_by_argkey = items_by_argkey[scopenum]
|
||||||
scoped_argkeys_cache = argkeys_cache[scopenum]
|
scoped_argkeys_cache = argkeys_cache[scopenum]
|
||||||
while items_deque:
|
while items_deque:
|
||||||
no_argkey_group: Dict[nodes.Item, None] = order_preserving_dict()
|
no_argkey_group: Dict[nodes.Item, None] = {}
|
||||||
slicing_argkey = None
|
slicing_argkey = None
|
||||||
while items_deque:
|
while items_deque:
|
||||||
item = items_deque.popleft()
|
item = items_deque.popleft()
|
||||||
if item in items_done or item in no_argkey_group:
|
if item in items_done or item in no_argkey_group:
|
||||||
continue
|
continue
|
||||||
argkeys = order_preserving_dict.fromkeys(
|
argkeys = dict.fromkeys(
|
||||||
(k for k in scoped_argkeys_cache.get(item, []) if k not in ignore), None
|
(k for k in scoped_argkeys_cache.get(item, []) if k not in ignore), None
|
||||||
)
|
)
|
||||||
if not argkeys:
|
if not argkeys:
|
||||||
|
|
|
@ -35,7 +35,6 @@ from _pytest._code import ExceptionInfo
|
||||||
from _pytest._code.code import ExceptionRepr
|
from _pytest._code.code import ExceptionRepr
|
||||||
from _pytest._io.wcwidth import wcswidth
|
from _pytest._io.wcwidth import wcswidth
|
||||||
from _pytest.compat import final
|
from _pytest.compat import final
|
||||||
from _pytest.compat import order_preserving_dict
|
|
||||||
from _pytest.config import _PluggyPlugin
|
from _pytest.config import _PluggyPlugin
|
||||||
from _pytest.config import Config
|
from _pytest.config import Config
|
||||||
from _pytest.config import ExitCode
|
from _pytest.config import ExitCode
|
||||||
|
@ -909,9 +908,7 @@ class TerminalReporter:
|
||||||
if not warning_reports:
|
if not warning_reports:
|
||||||
return
|
return
|
||||||
|
|
||||||
reports_grouped_by_message: Dict[str, List[WarningReport]] = (
|
reports_grouped_by_message: Dict[str, List[WarningReport]] = {}
|
||||||
order_preserving_dict()
|
|
||||||
)
|
|
||||||
for wr in warning_reports:
|
for wr in warning_reports:
|
||||||
reports_grouped_by_message.setdefault(wr.message, []).append(wr)
|
reports_grouped_by_message.setdefault(wr.message, []).append(wr)
|
||||||
|
|
||||||
|
@ -925,7 +922,7 @@ class TerminalReporter:
|
||||||
if len(locations) < 10:
|
if len(locations) < 10:
|
||||||
return "\n".join(map(str, locations))
|
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:
|
for loc in locations:
|
||||||
key = str(loc).split("::", 1)[0]
|
key = str(loc).split("::", 1)[0]
|
||||||
counts_by_filename[key] = counts_by_filename.get(key, 0) + 1
|
counts_by_filename[key] = counts_by_filename.get(key, 0) + 1
|
||||||
|
|
Loading…
Reference in New Issue