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

Nonlocal statement support #854

Merged
merged 32 commits into from Aug 7, 2018

Conversation

Projects
None yet
2 participants
@BPYap
Contributor

BPYap commented Jun 29, 2018

Nonlocal is used in some built-in module (e.g. tasks.py in asyncio module). Support for nonlocal statement should enable a number of files in KNOWN_PROBLEM_MODULES to compile.

Refer to GSOC week 10/11 log for implementation details.

New features added in this PR:

  • nonlocal is now supported in function closure and generator closure. e.g:
def func():
    a = 'a from outer'
    def nested_func():
        nonlocal a
        print(a)  # will print 'a from outer'
        a = 'a from inner'
        print(a)  # will print 'a from inner'

    nested_func()
    print(a)  # will print 'a from inner'

func()
  • Generator is now able to read variables from enclosing scopes. e.g:
def func():
    a = 'a from outer'
    def gen():
        print(a)  # will print 'a from outer'
        yield

    next(gen())

func()

BPYap added some commits Jul 2, 2018

@BPYap BPYap changed the title from Nonlocal statement support [WIP] to Nonlocal statement support Jul 4, 2018

BPYap added some commits Jul 4, 2018

Revert "Updated methods"
This reverts commit 6860a1d.
@BPYap

This comment has been minimized.

Contributor

BPYap commented Aug 2, 2018

@freakboy3742, passing #locals as storage space for closure variables seems to work well. To my surprise it even fixes the test_recursive_in_function case 😄

Well, some part of the code may still be further enhanced to be more efficient.
For now, only function and generator support closure/nonlocal. I'm thinking to add closure support for class and method at later time and in separate PR as they are not as important in getting asyncio to work.

@freakboy3742

👍 It took a while, but we finally got there! This looks a lot cleaner - excellent work!

@freakboy3742 freakboy3742 merged commit 0028447 into pybee:master Aug 7, 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:nonlocal-statement-support branch Aug 8, 2018

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