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

Fixed #866 RunTimeError when generator is nested in more than 1 level of function definition #867

Merged
merged 3 commits into from Jul 14, 2018

Conversation

Projects
None yet
2 participants
@BPYap
Contributor

BPYap commented Jul 12, 2018

On closer inspection, the reason for the RuntimeError in #866 was due to incorrect class path name.

Considering the code below (Test.py):

def wrapped():
    def func():
        def gen():
            yield 'Hello World'

        print(next(gen()))

    func()
    
wrapped()

The path to gen would be python.Test.func$gen, as indicated in compilation output:

Compiling Test.py ...
Writing .\python\Test.class ...
Writing .\python\Test\func.class ...
Writing .\python\Test\func$gen.class ...

However, during runtime, the path to gen becomes python.Test.func.gen instead of python.Test.func$gen, causing java.lang.ClassNotFoundException which is wrapped in RuntimeError.

The root cause is on line 1118 of methods.py, when declaring classpath of generator method, self.klass.class_name returns python.Test.func.gen. To fix this, I replaced it with self.class_descriptor.replace('/', '.') to get python.Test.func$gen

@freakboy3742

Patch makes sense, but needs a test

BPYap added some commits Jul 13, 2018

@BPYap

This comment has been minimized.

Contributor

BPYap commented Jul 13, 2018

@freakboy3742 Done 😄

@freakboy3742 freakboy3742 merged commit 7e9cdf2 into pybee:master Jul 14, 2018

5 checks passed

beekeeper:0/beefore:javacheckstyle Java lint checks passed.
Details
beekeeper:0/beefore:pycodestyle Python lint checks passed.
Details
beekeeper:1/smoke-test Smoke build (Python 3.4) passed.
Details
beekeeper:2/full-test:py3.5 Python 3.5 tests passed.
Details
beekeeper:2/full-test:py3.6 Python 3.6 tests passed.
Details

@BPYap BPYap deleted the BPYap:fix-nested-generator branch Jul 14, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment