rapidfuzz / Levenshtein

The Levenshtein Python C extension module contains functions for fast computation of Levenshtein distance and string similarity
https://rapidfuzz.github.io/Levenshtein
GNU General Public License v2.0
276 stars 16 forks source link

Levenshtein.matching_blocks raising AttributeError in latest release #29

Closed atomflunder closed 2 years ago

atomflunder commented 2 years ago

Hello, I just tried upgrading to the latest release, v0.20.0, and I noticed the Levenshtein.matching_blocks() function now produces an error when used.

The code with the error message:

>>> import Levenshtein
>>> long_string = "hsfdjuhfkjsnfjknskj"
>>> short_string = "hsfdsjdsai"
>>> ops = Levenshtein.editops(long_string, short_string)
>>> Levenshtein.matching_blocks(ops, long_string, short_string)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\my_name\Documents\Python\my_project\venv\lib\site-packages\Levenshtein\__init__.py", line 164, in matching_blocks
    return _Editops(edit_operations, len1, len2).as_matching_blocks().as_list()
AttributeError: 'list' object has no attribute 'as_list'

When downgrading to version v0.19.3 everything works as intended:

>>> import Levenshtein
>>> long_string = "hsfdjuhfkjsnfjknskj"
>>> short_string = "hsfdsjdsai"
>>> ops = Levenshtein.editops(long_string, short_string)
>>> Levenshtein.matching_blocks(ops, long_string, short_string)
[(0, 0, 4), (10, 4, 1), (13, 5, 1), (16, 7, 1), (19, 10, 0)]

In both examples the rapidfuzz version is 2.3.0.

Thanks in advance for responding!

maxbachmann commented 2 years ago

Thanks for reporting. This is fixed in v0.20.1

atomflunder commented 2 years ago

Thank you for the quick fix!