Skip to content

difflib.SequenceMatcher stores matching blocks as tuples, not Match named tuples #65834

Closed

Description

@drevicko
mannequin
BPO 21635
Nosy @tim-one, @rhettinger, @terryjreedy

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = 'https://github.com/rhettinger'
closed_at = <Date 2014-06-21.19:05:02.773>
created_at = <Date 2014-06-02.10:03:56.123>
labels = ['type-bug', 'library']
title = 'difflib.SequenceMatcher stores matching blocks as tuples, not Match named tuples'
updated_at = <Date 2014-06-21.19:05:02.772>
user = 'https://bugs.python.org/drevicko'

bugs.python.org fields:

activity = <Date 2014-06-21.19:05:02.772>
actor = 'rhettinger'
assignee = 'rhettinger'
closed = True
closed_date = <Date 2014-06-21.19:05:02.773>
closer = 'rhettinger'
components = ['Library (Lib)']
creation = <Date 2014-06-02.10:03:56.123>
creator = 'drevicko'
dependencies = []
files = []
hgrepos = []
issue_num = 21635
keywords = []
message_count = 5.0
messages = ['219565', '219906', '221153', '221183', '221186']
nosy_count = 5.0
nosy_names = ['tim.peters', 'rhettinger', 'terry.reedy', 'python-dev', 'drevicko']
pr_nums = []
priority = 'high'
resolution = 'fixed'
stage = 'needs patch'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue21635'
versions = ['Python 2.7', 'Python 3.4', 'Python 3.5']

Activity

  1. drevicko commented on Jun 2, 2014

    drevickomannequin
    MannequinAuthor

    difflib.SequenceMatcher.get_matching_blocks() last lines:

        non_adjacent.append( (la, lb, 0) )
        self.matching_blocks = non_adjacent
        return map(Match._make, self.matching_blocks)
    

    should be something like:

        non_adjacent.append( (la, lb, 0) )
        self.matching_blocks = map(Match._make, non_adjacent)
        return self.matching_blocks
    
  2. added
    stdlibStandard Library Python modules in the Lib/ directory
    type-bugAn unexpected behavior, bug, or error
    on Jun 2, 2014
  3. terryjreedy commented on Jun 7, 2014

    @terryjreedy
    Member

    Why do you think this is a bug? What behavior both looks wrong and gets improved by the change?

  4. self-assigned this
    on Jun 21, 2014
  5. rhettinger commented on Jun 21, 2014

    @rhettinger
    Contributor

    What behavior both looks wrong and gets improved by the change?

    The incorrect behavior is that matching_blocks is incorrectly cached so that calls to get_matching_blocks() returns an answer without the named tuple (in contravention of the documented behavior):

    >>> s = SequenceMatcher(None, "abxcd", "abcd")
    >>> s.get_matching_blocks()
    [Match(a=0, b=0, size=2), Match(a=3, b=2, size=2), Match(a=5, b=4, size=0)]
    >>> s.get_matching_blocks()
    [(0, 0, 2), (3, 2, 2), (5, 4, 0)]
    >>> s.get_matching_blocks()
    [(0, 0, 2), (3, 2, 2), (5, 4, 0)]
  6. python-dev commented on Jun 21, 2014

    python-devmannequin
    Mannequin

    New changeset f02a563ad1bf by Raymond Hettinger in branch '2.7':
    bpo-21635: Fix caching in difflib.SequenceMatcher.get_matching_blocks().
    http://hg.python.org/cpython/rev/f02a563ad1bf

  7. python-dev commented on Jun 21, 2014

    python-devmannequin
    Mannequin

    New changeset ed73c127421c by Raymond Hettinger in branch '3.4':
    bpo-21635: Fix caching in difflib.SequenceMatcher.get_matching_blocks().
    http://hg.python.org/cpython/rev/ed73c127421c

  8. transferred this issue fromon Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions