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
45750109
Commit
45750109
authored
Jun 21, 2014
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue 21635: Fix caching in difflib.SequenceMatcher.get_matching_blocks().
parent
94919a44
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
2 deletions
+15
-2
Lib/difflib.py
Lib/difflib.py
+2
-2
Lib/test/test_difflib.py
Lib/test/test_difflib.py
+9
-0
Misc/NEWS
Misc/NEWS
+4
-0
No files found.
Lib/difflib.py
View file @
45750109
...
@@ -523,8 +523,8 @@ class SequenceMatcher:
...
@@ -523,8 +523,8 @@ class SequenceMatcher:
non_adjacent
.
append
((
i1
,
j1
,
k1
))
non_adjacent
.
append
((
i1
,
j1
,
k1
))
non_adjacent
.
append
(
(
la
,
lb
,
0
)
)
non_adjacent
.
append
(
(
la
,
lb
,
0
)
)
self
.
matching_blocks
=
non_adjacent
self
.
matching_blocks
=
map
(
Match
.
_make
,
non_adjacent
)
return
map
(
Match
.
_make
,
self
.
matching_blocks
)
return
self
.
matching_blocks
def
get_opcodes
(
self
):
def
get_opcodes
(
self
):
"""Return list of 5-tuples describing how to turn a into b.
"""Return list of 5-tuples describing how to turn a into b.
...
...
Lib/test/test_difflib.py
View file @
45750109
...
@@ -59,6 +59,15 @@ class TestSFbugs(unittest.TestCase):
...
@@ -59,6 +59,15 @@ class TestSFbugs(unittest.TestCase):
diff_gen
=
difflib
.
unified_diff
([],
[])
diff_gen
=
difflib
.
unified_diff
([],
[])
self
.
assertRaises
(
StopIteration
,
diff_gen
.
next
)
self
.
assertRaises
(
StopIteration
,
diff_gen
.
next
)
def
test_matching_blocks_cache
(
self
):
# Issue #21635
s
=
difflib
.
SequenceMatcher
(
None
,
"abxcd"
,
"abcd"
)
first
=
s
.
get_matching_blocks
()
second
=
s
.
get_matching_blocks
()
self
.
assertEqual
(
second
[
0
].
size
,
2
)
self
.
assertEqual
(
second
[
1
].
size
,
2
)
self
.
assertEqual
(
second
[
2
].
size
,
0
)
def
test_added_tab_hint
(
self
):
def
test_added_tab_hint
(
self
):
# Check fix for bug #1488943
# Check fix for bug #1488943
diff
=
list
(
difflib
.
Differ
().
compare
([
"
\
t
I am a buggy"
],[
"
\
t
\
t
I am a bug"
]))
diff
=
list
(
difflib
.
Differ
().
compare
([
"
\
t
I am a buggy"
],[
"
\
t
\
t
I am a bug"
]))
...
...
Misc/NEWS
View file @
45750109
...
@@ -31,6 +31,10 @@ Library
...
@@ -31,6 +31,10 @@ Library
- Issue #21491: SocketServer: Fix a race condition in child processes reaping.
- Issue #21491: SocketServer: Fix a race condition in child processes reaping.
- Issue #21635: The difflib SequenceMatcher.get_matching_blocks() method
cache didn'
t
match
the
actual
result
.
The
former
was
a
list
of
tuples
and
the
latter
was
a
list
of
named
tuples
.
-
Issue
#
21722
:
The
distutils
"upload"
command
now
exits
with
a
non
-
zero
-
Issue
#
21722
:
The
distutils
"upload"
command
now
exits
with
a
non
-
zero
return
code
when
uploading
fails
.
Patch
by
Martin
Dengler
.
return
code
when
uploading
fails
.
Patch
by
Martin
Dengler
.
...
...
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