summaryrefslogtreecommitdiff
path: root/src/_pytest/compat.py
diff options
context:
space:
mode:
authorRan Benita <ran@unusedvar.com>2020-04-30 15:49:20 +0300
committerRan Benita <ran@unusedvar.com>2020-05-06 11:58:28 +0300
commitfcc473ab1c3891c410cc3ea362619a56731787a8 (patch)
treef1c54721912126225e9b08f88bef34f300ae3098 /src/_pytest/compat.py
parent4787fd64a4ca0dba5528b5651bddd254102fe9f3 (diff)
downloadpytest-fcc473ab1c3891c410cc3ea362619a56731787a8.tar.gz
Use dict instead of OrderedDict on Python 3.7
OrderedDict is quite a bit heavier than just a dict.
Diffstat (limited to 'src/_pytest/compat.py')
-rw-r--r--src/_pytest/compat.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/_pytest/compat.py b/src/_pytest/compat.py
index ba225eb8f..6a0614f01 100644
--- a/src/_pytest/compat.py
+++ b/src/_pytest/compat.py
@@ -381,3 +381,15 @@ else:
return self
value = instance.__dict__[self.func.__name__] = self.func(instance)
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