FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Speed-up lazy heapq import in collections by rhettinger · Pull Request #127538 · python/cpython · GitHub

Repository navigation

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
7 changes: 6 additions & 1 deletion Lib/collections/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
except ImportError:
pass

heapq = None # Lazily imported


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

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

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

def elements(self):
Expand Down

Back | FazBrowse Home | New Git URL