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

Should the Python "global" statement be accepted and ignored? #20

Open
lelit opened this issue Jan 25, 2017 · 3 comments
Open

Should the Python "global" statement be accepted and ignored? #20

lelit opened this issue Jan 25, 2017 · 3 comments

Comments

@lelit
Copy link
Contributor

lelit commented Jan 25, 2017

In JS there isn't an equivalent of the global statement in Python: in a sense, a variable is automatically put in the global scope when it is not declared, so the following snippet behaves differently when run under Python than under JS:

some_global = None

def get_global():
    if some_global:
        return some_global
    # compute it
    some_global = 'foo'
    return some_global

Python itself would raise an UnboundLocalError, while pyflakes reports local variable 'some_global' (defined in enclosing scope on line 1) referenced before assignment.

So I wonder whether pj could/should allow me to put a global statement in that function, adding a null-transform for its node type, in other words simply ignoring the declaration. It would be a bonus if it could even check for the existence of those global(s), just to avoid typos...

@azazel75
Copy link
Collaborator

i'm not sure if JavaScripthon shoud work as a generic syntax-checker, especially on a statement that it sould ignore ;-)

@lelit
Copy link
Contributor Author

lelit commented Jan 25, 2017

Do you foresee possible negative effects in my proposal?

@azazel75
Copy link
Collaborator

One, the fact that when someone uses JavaScripthon he may think that it also does some kind code checking, more than what the Python's parser alone does. It is not... I think that if a this has to be implemented, the scope checking has to be activated with an option like '--enable-scope-checks' on cmdline

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

No branches or pull requests

2 participants