mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
bpo-45000: Raise SyntaxError when try to delete __debug__ (GH-27947)
Automerge-Triggered-By: GH:pablogsal
This commit is contained in:
parent
24da544014
commit
551da597a0
4 changed files with 12 additions and 0 deletions
|
@ -176,6 +176,8 @@ Other CPython Implementation Changes
|
||||||
support :class:`typing.SupportsComplex` and :class:`typing.SupportsBytes` protocols.
|
support :class:`typing.SupportsComplex` and :class:`typing.SupportsBytes` protocols.
|
||||||
(Contributed by Mark Dickinson and Dong-hee Na in :issue:`24234`.)
|
(Contributed by Mark Dickinson and Dong-hee Na in :issue:`24234`.)
|
||||||
|
|
||||||
|
* A :exc:`SyntaxError` (instead of a :exc:`NameError`) will be raised when deleting the :const:`__debug__` constant. (Contributed by Dong-hee Na in :issue:`45000`.)
|
||||||
|
|
||||||
|
|
||||||
New Modules
|
New Modules
|
||||||
===========
|
===========
|
||||||
|
|
|
@ -59,6 +59,10 @@ SyntaxError: cannot assign to __debug__
|
||||||
Traceback (most recent call last):
|
Traceback (most recent call last):
|
||||||
SyntaxError: cannot assign to __debug__
|
SyntaxError: cannot assign to __debug__
|
||||||
|
|
||||||
|
>>> del __debug__
|
||||||
|
Traceback (most recent call last):
|
||||||
|
SyntaxError: cannot delete __debug__
|
||||||
|
|
||||||
>>> f() = 1
|
>>> f() = 1
|
||||||
Traceback (most recent call last):
|
Traceback (most recent call last):
|
||||||
SyntaxError: cannot assign to function call here. Maybe you meant '==' instead of '='?
|
SyntaxError: cannot assign to function call here. Maybe you meant '==' instead of '='?
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
A :exc:`SyntaxError` is now raised when trying to delete :const:`__debug__`.
|
||||||
|
Patch by Dong-hee Na.
|
|
@ -2343,6 +2343,10 @@ forbidden_name(struct compiler *c, identifier name, expr_context_ty ctx)
|
||||||
compiler_error(c, "cannot assign to __debug__");
|
compiler_error(c, "cannot assign to __debug__");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
if (ctx == Del && _PyUnicode_EqualToASCIIString(name, "__debug__")) {
|
||||||
|
compiler_error(c, "cannot delete __debug__");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue