-
-
Notifications
You must be signed in to change notification settings - Fork 33k
gh-138890: Add clearer message when deleting builtins with del
#139078
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
base: main
Are you sure you want to change the base?
Conversation
Python/generated_cases.c.h
Outdated
UNBOUNDLOCAL_ERROR_MSG, | ||
PyTuple_GetItem(_PyFrame_GetCode(frame)->co_localsplusnames, oparg) | ||
); | ||
name = PyTuple_GetItem(_PyFrame_GetCode(frame)->co_localsplusnames, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it is better no to break the declaration and the assignment?
Python/generated_cases.c.h
Outdated
name = PyTuple_GetItem(_PyFrame_GetCode(frame)->co_localsplusnames, | ||
oparg); | ||
const char *err_msg = PyMapping_HasKey(BUILTINS(), name) | ||
? CANNOT_DELETE_BUILTIN_ERROR_MSG |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is better to proper align these two lines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't generated_cases.c.h
be left without review?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is a generated file.
Python/bytecodes.c
Outdated
ERROR_NO_POP(); | ||
} | ||
if (err == 0) { | ||
const char *err_msg = PyMapping_HasKey(BUILTINS(), name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it is safe to use PyDict_*
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no PyDict_*
equivalent of PyMapping_HasKey
, but we should be using PyMapping_HasKeyWithError
here.
Python/bytecodes.c
Outdated
ERROR_NO_POP(); | ||
} | ||
if (err == 0) { | ||
const char *err_msg = PyMapping_HasKey(BUILTINS(), name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no PyDict_*
equivalent of PyMapping_HasKey
, but we should be using PyMapping_HasKeyWithError
here.
Python/bytecodes.c
Outdated
PyTuple_GetItem(_PyFrame_GetCode(frame)->co_localsplusnames, oparg) | ||
); | ||
PyObject *name; | ||
name = PyTuple_GetItem(_PyFrame_GetCode(frame)->co_localsplusnames, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PyTuple_GetItem
can fail. We should be able to expect that it can't, so let's use PyTuple_GET_ITEM
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we leave this as is? This seems like an unrelated change.
Python/bytecodes.c
Outdated
PyObject *name; | ||
name = PyTuple_GetItem(_PyFrame_GetCode(frame)->co_localsplusnames, | ||
oparg); | ||
const char *err_msg = PyMapping_HasKey(BUILTINS(), name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto -- we should be using PyMapping_HasKeyWithError
.
@@ -0,0 +1 @@ | |||
Deleting builtin names with ``del`` now gives a clearer error message. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deleting builtin names with ``del`` now gives a clearer error message. | |
Deleting built-in names with :keyword:`del` now gives a clearer error message. |
Lib/test/test_scope.py
Outdated
|
||
def test_builtin_deletion_err_message(self): | ||
with self.assertRaisesRegex( | ||
NameError, "cannot delete builtin 'all'" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The formatting makes this a bit difficult to read. This isn't coming near PEP 8's 79 character limit, so let's just keep all the arguments on the same line. This applies to all the assertRaisesRegex
calls below.
Try to fit C code in reasonable width
Uh oh!
There was an error while loading. Please reload this page.