Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StopIteration & RuntimeError fix for Python >= 3.7 #294

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

NicolasBizzozzero
Copy link

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: piskvorky/gensim#2438).

This PR fixes the _read generator by removing the StopIteration exception raised in it. It solves the following issues :

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.3%) to 68.022% when pulling 66ab344 on NicolasBizzozzero:master into 5b85d99 on clips:master.

@zc4242
Copy link

zc4242 commented Mar 10, 2020

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...

@tuky
Copy link

tuky commented Apr 21, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants