You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As mentioned in #29 Unicode strings are not properly handled when using Python 2 and lead to exceptions.
This fix makes sure that Unicode string encoding works for Python 2 and Python 3 as well.
Python 3 uses unicode by default while python 2 differentiates between ASCII and unicode.
Therefore, if text.encode('utf-8') is applied on an (encoded) unicode string in python 2 it will result in UnicodeDecodeError: 'ascii' codec can't decode byte ... in position 1: ordinal not in range(128).
Longer Explanation:
In python 3, type(u'Köln') and type('Köln') both give <class 'str'> and class 'str' is encoded to class 'bytes'.
In python 2, type(u'Köln') gives <type 'unicode'>, type('Köln') gives <type 'str'>, and type 'unicode' is encoded to type 'str'.
Since function annotate() requires input of type 'str' any unicode string in python 2 has to be passed as encoded 'str' and further calls of text.encode('utf-8') will result in UnicodeDecodeError.
Consequently, text.encode('utf-8') should only be called in python 3.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
As mentioned in #29 Unicode strings are not properly handled when using Python 2 and lead to exceptions.
This fix makes sure that Unicode string encoding works for Python 2 and Python 3 as well.