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

Separate ns variable in eval_code into globals and locals #1083

Merged
merged 11 commits into from
Jan 10, 2021

Conversation

hoodmane
Copy link
Member

@hoodmane hoodmane commented Jan 9, 2021

This will allow pyodide.js to avoid pollution of global namespace by using eval_code with new empty dict.

@hoodmane hoodmane force-pushed the ns_to_globals_locals branch from 705216a to ec65552 Compare January 9, 2021 04:31
@casatir
Copy link
Contributor

casatir commented Jan 9, 2021

+1 for this. As a side effect, it replaces the ns parameter which I found not really explicit.

src/pyodide-py/pyodide/_base.py Show resolved Hide resolved
@casatir
Copy link
Contributor

casatir commented Jan 9, 2021

avoid pollution of global namespace

Can you add some tests that demonstrate this please?

@hoodmane
Copy link
Member Author

hoodmane commented Jan 9, 2021

Can you add some tests that demonstrate this please?

Of course =)

@hoodmane
Copy link
Member Author

hoodmane commented Jan 9, 2021

@casatir How's that look for a test?

Copy link
Member

@rth rth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree it very useful. Please add a changelog entry.

src/pyodide-py/pyodide/_base.py Show resolved Hide resolved
Copy link
Member

@rth rth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few remaining comments, otherwise LGTM. Thanks.

Also please add a changelog entry.

src/pyodide-py/pyodide/_base.py Outdated Show resolved Hide resolved
src/pyodide-py/pyodide/_base.py Outdated Show resolved Hide resolved
src/pyodide-py/pyodide/_base.py Outdated Show resolved Hide resolved
src/pyodide-py/pyodide/_base.py Outdated Show resolved Hide resolved
@hoodmane
Copy link
Member Author

hoodmane commented Jan 9, 2021

I also changed mode ==> return_mode (more explicit) and changed it so that it will raise an error if passed an unexpected mode. Otherwise it's way too easy for someone to pass i.e., "last-expr-or-assign" or "last_exp_or_assign" and be confused when it does something different than expected. It could be friendly to offer:

class ReturnMode:
    LAST_EXPR = "last_expr"
    LAST_EXPR_OR_ASSIGN = "last_expr_or_assign"
    NONE = None

which would make Jedi more helpful for instance.

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.

3 participants