Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions Lib/collections/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
_sys.modules['collections.abc'] = _collections_abc
abc = _collections_abc

lazy from copy import copy as _copy
lazy from heapq import nlargest as _nlargest
from itertools import chain as _chain
from itertools import repeat as _repeat
from itertools import starmap as _starmap
Expand Down Expand Up @@ -59,8 +61,6 @@
except ImportError:
pass

heapq = None # Lazily imported


################################################################################
### OrderedDict
Expand Down Expand Up @@ -634,12 +634,7 @@ def most_common(self, n=None):
if n is None:
return sorted(self.items(), key=_itemgetter(1), reverse=True)

# Lazy import to speedup Python startup time
global heapq
if heapq is None:
import heapq

return heapq.nlargest(n, self.items(), key=_itemgetter(1))
return _nlargest(n, self.items(), key=_itemgetter(1))

def elements(self):
'''Iterator over elements repeating each as many times as its count.
Expand Down Expand Up @@ -1249,11 +1244,10 @@ def __copy__(self):
def copy(self):
if self.__class__ is UserDict:
return UserDict(self.data.copy())
import copy
data = self.data
try:
self.data = {}
c = copy.copy(self)
c = _copy(self)
finally:
self.data = data
c.update(self)
Expand Down
Loading