Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
39659f22
Commit
39659f22
authored
Sep 14, 2013
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #19018: The heapq.merge() function no longer suppresses IndexError
parent
bf7e8656
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
5 deletions
+24
-5
Lib/heapq.py
Lib/heapq.py
+10
-5
Lib/test/test_heapq.py
Lib/test/test_heapq.py
+9
-0
Misc/ACKS
Misc/ACKS
+2
-0
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/heapq.py
View file @
39659f22
...
...
@@ -366,6 +366,7 @@ def merge(*iterables):
'''
_heappop
,
_heapreplace
,
_StopIteration
=
heappop
,
heapreplace
,
StopIteration
_len
=
len
h
=
[]
h_append
=
h
.
append
...
...
@@ -377,17 +378,21 @@ def merge(*iterables):
pass
heapify
(
h
)
while
1
:
while
_len
(
h
)
>
1
:
try
:
while
1
:
v
,
itnum
,
next
=
s
=
h
[
0
]
# raises IndexError when h is empty
while
True
:
v
,
itnum
,
next
=
s
=
h
[
0
]
yield
v
s
[
0
]
=
next
()
# raises StopIteration when exhausted
_heapreplace
(
h
,
s
)
# restore heap condition
except
_StopIteration
:
_heappop
(
h
)
# remove empty iterator
except
IndexError
:
return
if
h
:
# fast case when only a single iterator remains
v
,
itnum
,
next
=
h
[
0
]
yield
v
for
v
in
next
.
__self__
:
yield
v
# Extend the implementations of nsmallest and nlargest to use a key= argument
_nsmallest
=
nsmallest
...
...
Lib/test/test_heapq.py
View file @
39659f22
...
...
@@ -158,6 +158,15 @@ class TestHeap(TestCase):
self
.
assertEqual
(
sorted
(
chain
(
*
inputs
)),
list
(
self
.
module
.
merge
(
*
inputs
)))
self
.
assertEqual
(
list
(
self
.
module
.
merge
()),
[])
def
test_merge_does_not_suppress_index_error
(
self
):
# Issue 19018: Heapq.merge suppresses IndexError from user generator
def
iterable
():
s
=
list
(
range
(
10
))
for
i
in
range
(
20
):
yield
s
[
i
]
# IndexError when i > 10
with
self
.
assertRaises
(
IndexError
):
list
(
self
.
module
.
merge
(
iterable
(),
iterable
()))
def
test_merge_stability
(
self
):
class
Int
(
int
):
pass
...
...
Misc/ACKS
View file @
39659f22
...
...
@@ -110,6 +110,7 @@ Paul Boddie
Matthew Boedicker
Robin Boerdijk
David Bolen
Wouter Bolsterlee
Gawain Bolton
Gregory Bond
Jurjen Bos
...
...
@@ -313,6 +314,7 @@ Nils Fischbeck
Frederik Fix
Matt Fleming
Hernán Martínez Foffani
Artem Fokin
Arnaud Fontaine
Michael Foord
Amaury Forgeot d'Arc
...
...
Misc/NEWS
View file @
39659f22
...
...
@@ -35,6 +35,9 @@ Library
- Issue #17324: Fix http.server'
s
request
handling
case
on
trailing
'/'
.
Patch
contributed
by
Vajrasky
Kok
.
-
Issue
#
19018
:
The
heapq
.
merge
()
function
no
longer
suppresses
IndexError
in
the
underlying
iterables
.
-
Issue
#
18784
:
The
uuid
module
no
more
attempts
to
load
libc
via
ctypes
.
CDLL
,
if
all
necessary
functions
are
already
found
in
libuuid
.
Patch
by
Evgeny
Sologubov
.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment