ztane / python-Levenshtein

The Levenshtein Python C extension module contains functions for fast computation of Levenshtein distance and string similarity
GNU General Public License v2.0
1.26k stars 155 forks source link

apply_edit gives error on Python 3.3 #5

Closed Hodapp87 closed 9 years ago

Hodapp87 commented 10 years ago

Taking the example code from the help for Levenshtein.apply_edit:

from Levenshtein import *
e = editops('man', 'scotsman')
apply_edit(e, 'man', 'scotsman')
apply_edit(e[:3], 'man', 'scotsman')

This works fine on Python 2.7.6:

Python 2.7.6 (default, Nov 26 2013, 12:52:49) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from Levenshtein import *
>>> e = editops('man', 'scotsman')
>>> apply_edit(e, 'man', 'scotsman')
'scotsman'
>>> apply_edit(e[:3], 'man', 'scotsman')
'scoman'

However, it gives an error on Python 3.3.3:

Python 3.3.3 (default, Nov 26 2013, 13:33:18) 
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from Levenshtein import *
>>> e = editops('man', 'scotsman')
>>> apply_edit(e, 'man', 'scotsman')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: apply_edit first argument must be a List of edit operations
>>> apply_edit(e[:3], 'man', 'scotsman')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: apply_edit first argument must be a List of edit operations

http://www.python-forum.de/viewtopic.php?f=1&t=32969 seems to indicate the same.

ztane commented 10 years ago

Indeed, this occurs because string_to_edittype(PyObject *string) only seems to support C PyString, that is str on python 2 and bytes on python 3.

ztane commented 9 years ago

Fixed in 0.12