Skip to content

Commit bf81161

Browse files
author
Paul Sokolovsky
committed
heapq: Import itertools only for functions which really require it.
1 parent 3de1406 commit bf81161

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

heapq/heapq.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@
127127
__all__ = ['heappush', 'heappop', 'heapify', 'heapreplace', 'merge',
128128
'nlargest', 'nsmallest', 'heappushpop']
129129

130-
from itertools import islice, count, tee, chain
130+
#from itertools import count, tee, chain
131131

132132
def heappush(heap, item):
133133
"""Push item onto heap, maintaining the heap invariant."""
@@ -197,6 +197,7 @@ def nlargest(n, iterable):
197197
198198
Equivalent to: sorted(iterable, reverse=True)[:n]
199199
"""
200+
from itertools import islice, count, tee, chain
200201
if n < 0:
201202
return []
202203
it = iter(iterable)
@@ -215,6 +216,7 @@ def nsmallest(n, iterable):
215216
216217
Equivalent to: sorted(iterable)[:n]
217218
"""
219+
from itertools import islice, count, tee, chain
218220
if n < 0:
219221
return []
220222
it = iter(iterable)
@@ -392,6 +394,7 @@ def nsmallest(n, iterable, key=None):
392394
393395
Equivalent to: sorted(iterable, key=key)[:n]
394396
"""
397+
from itertools import islice, count, tee, chain
395398
# Short-cut for n==1 is to use min() when len(iterable)>0
396399
if n == 1:
397400
it = iter(iterable)
@@ -430,6 +433,7 @@ def nlargest(n, iterable, key=None):
430433
Equivalent to: sorted(iterable, key=key, reverse=True)[:n]
431434
"""
432435

436+
from itertools import islice, count, tee, chain
433437
# Short-cut for n==1 is to use max() when len(iterable)>0
434438
if n == 1:
435439
it = iter(iterable)

heapq/metadata.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
srctype = cpython
22
type = module
3-
version = 0.9.1
3+
version = 0.9.2
44
# Module uses in *some* functions, but we don't want to depend on it
55
#depends = itertools

heapq/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
setup(name='micropython-heapq',
9-
version='0.9.1',
9+
version='0.9.2',
1010
description='CPython heapq module ported to MicroPython',
1111
long_description='This is a module ported from CPython standard library to be compatible with\nMicroPython interpreter. Usually, this means applying small patches for\nfeatures not supported (yet, or at all) in MicroPython. Sometimes, heavier\nchanges are required. Note that CPython modules are written with availability\nof vast resources in mind, and may not work for MicroPython ports with\nlimited heap. If you are affected by such a case, please help reimplement\nthe module from scratch.',
1212
url='https://github.com/micropython/micropython/issues/405',

0 commit comments

Comments
 (0)