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
Assignment operator allows to assign to __debug__ #80233
Comments
All ways of assigning to __debug__ are forbidden: >>> __debug__ = 1
File "<stdin>", line 1
SyntaxError: cannot assign to __debug__
>>> for __debug__ in []: pass
...
File "<stdin>", line 1
SyntaxError: cannot assign to __debug__
>>> with cm() as __debug__: pass
...
File "<stdin>", line 1
SyntaxError: cannot assign to __debug__
>>> class __debug__: pass
...
File "<stdin>", line 1
SyntaxError: cannot assign to __debug__
>>> def __debug__(): pass
...
File "<stdin>", line 1
SyntaxError: cannot assign to __debug__
>>> def foo(__debug__): pass
...
File "<stdin>", line 1
SyntaxError: cannot assign to __debug__
>>> import __debug__
File "<stdin>", line 1
SyntaxError: cannot assign to __debug__ The only exception is the assignment operator. >>> (__debug__ := 'spam')
'spam'
>>> globals()['__debug__']
'spam' This looks like a bug. |
An idea for the fix? a direction where I could find the solution? ;-) |
You need to add for the target of the assignment operator the same check as for other targets. |
ok, I will check for the assignment operator in the code. maybe in the AST (Python-ast.c) but I think not |
You should look in Python/ast.c. The naming convention follows some form of "named expression" (e.g. NamedExpr, ast_for_namedexpr). I'll have more time to look later this week, but let me know if you have any questions. |
Hi @Emily Thank you for your help. In fact, I have started to read Python-ast.c and ast.c, they are the main files for this kind of operations. Thank you again, |
Look at compile.c. The code for restricting other assignments is located here. |
When I started working on this I did not notice the extra comments here. I will close my PR so Stéphane can do the PR. |
Thank you Pablo, if I see you at PyCon, maybe we could drink a good beer ;-) |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: