StopIteration & RuntimeError fix for Python >= 3.7
Since Python 3.7, all StopIteration exceptions raised inside a generator are transformed into RuntimeError (see PEP-0479 and this answer from StackOverflow). This new behavior made pattern unusable for all Python3.7+ users and all packages depending on it (gensim for instance: https://github.com/RaRe-Technologies/gensim/issues/2438).
This PR fixes the _read generator by removing the StopIteration exception raised in it. It solves the following issues :
- https://github.com/clips/pattern/issues/243
- https://github.com/clips/pattern/issues/282
- https://github.com/clips/pattern/issues/283
- https://github.com/clips/pattern/issues/288
- https://github.com/RaRe-Technologies/gensim/issues/2438
Coverage decreased (-0.3%) to 68.022% when pulling 66ab34453a3443c06a4ebda092c8d1947c83b17a on NicolasBizzozzero:master into 5b85d998c30ddc6772b56310713530224466083a on clips:master.
Thank you for all the work @NicolasBizzozzero !
Seems like the CI build is based on python=3.6 and causing the check failures? Who can help to fix this issue as it seems stupid to not able to fix this for quite a while...
Meanwhile you can monkey patch around this issue by calling this method in your module:
def patch_pattern():
from pattern import text
original_read = text._read
@functools.wraps(original_read)
def patched_read(*args, **kwargs):
try:
for r in original_read(*args, **kwargs):
yield r
except RuntimeError:
pass
text._read = patched_read