Skip to content

Commit 9c94cbe

Browse files
committed
Make some styling changes.
Try to fit C code in reasonable width
1 parent 8bf802d commit 9c94cbe

File tree

5 files changed

+97
-66
lines changed

5 files changed

+97
-66
lines changed

Lib/test/test_scope.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -836,26 +836,20 @@ def g(self, __arg):
836836
closure(_MultiplyNested__arg=2)
837837

838838
def test_builtin_deletion_err_message(self):
839-
with self.assertRaisesRegex(
840-
NameError, "cannot delete builtin 'all'"
841-
):
839+
with self.assertRaisesRegex(NameError, "cannot delete builtin 'all'"):
842840
del all
843841

844842
def f():
845843
del all
846844

847-
with self.assertRaisesRegex(
848-
UnboundLocalError, "cannot delete builtin 'all'"
849-
):
845+
with self.assertRaisesRegex(UnboundLocalError, "cannot delete builtin 'all'"):
850846
f()
851847

852848
def g():
853849
global all
854850
del all
855851

856-
with self.assertRaisesRegex(
857-
NameError, "cannot delete builtin 'all'"
858-
):
852+
with self.assertRaisesRegex(NameError, "cannot delete builtin 'all'"):
859853
g()
860854

861855

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Deleting builtin names with ``del`` now gives a clearer error message.
1+
Deleting built-in names with :keyword:`del` now gives a clearer error message.

Python/bytecodes.c

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,10 +1577,13 @@ dummy_func(
15771577
err = PyObject_DelItem(ns, name);
15781578
// Can't use ERROR_IF here.
15791579
if (err != 0) {
1580-
const char *err_msg = PyMapping_HasKey(BUILTINS(), name)
1581-
? CANNOT_DELETE_BUILTIN_ERROR_MSG
1582-
: NAME_ERROR_MSG;
1583-
_PyEval_FormatExcCheckArg(tstate, PyExc_NameError, err_msg, name);
1580+
if (PyMapping_HasKeyWithError(BUILTINS(), name) == 1) {
1581+
_PyEval_FormatExcCheckArg(tstate, PyExc_NameError,
1582+
CANNOT_DELETE_BUILTIN_ERROR_MSG, name);
1583+
} else {
1584+
_PyEval_FormatExcCheckArg(tstate, PyExc_NameError,
1585+
NAME_ERROR_MSG, name);
1586+
}
15841587
ERROR_NO_POP();
15851588
}
15861589
}
@@ -1721,11 +1724,13 @@ dummy_func(
17211724
ERROR_NO_POP();
17221725
}
17231726
if (err == 0) {
1724-
const char *err_msg = PyMapping_HasKey(BUILTINS(), name)
1725-
? CANNOT_DELETE_BUILTIN_ERROR_MSG
1726-
: NAME_ERROR_MSG;
1727-
_PyEval_FormatExcCheckArg(tstate, PyExc_NameError,
1728-
err_msg, name);
1727+
if (PyMapping_HasKeyWithError(BUILTINS(), name) == 1) {
1728+
_PyEval_FormatExcCheckArg(tstate, PyExc_NameError,
1729+
CANNOT_DELETE_BUILTIN_ERROR_MSG, name);
1730+
} else {
1731+
_PyEval_FormatExcCheckArg(tstate, PyExc_NameError,
1732+
NAME_ERROR_MSG, name);
1733+
}
17291734
ERROR_NO_POP();
17301735
}
17311736
}
@@ -1892,13 +1897,15 @@ dummy_func(
18921897
inst(DELETE_FAST, (--)) {
18931898
_PyStackRef v = GETLOCAL(oparg);
18941899
if (PyStackRef_IsNull(v)) {
1895-
PyObject *name;
1896-
name = PyTuple_GetItem(_PyFrame_GetCode(frame)->co_localsplusnames,
1897-
oparg);
1898-
const char *err_msg = PyMapping_HasKey(BUILTINS(), name)
1899-
? CANNOT_DELETE_BUILTIN_ERROR_MSG
1900-
: UNBOUNDLOCAL_ERROR_MSG;
1901-
_PyEval_FormatExcCheckArg(tstate, PyExc_UnboundLocalError, err_msg, name);
1900+
PyObject *localsplusnames = _PyFrame_GetCode(frame)->co_localsplusnames;
1901+
PyObject *name = PyTuple_GetItem(localsplusnames, oparg);
1902+
if (PyMapping_HasKeyWithError(BUILTINS(), name) == 1) {
1903+
_PyEval_FormatExcCheckArg(tstate, PyExc_UnboundLocalError,
1904+
CANNOT_DELETE_BUILTIN_ERROR_MSG, name);
1905+
} else {
1906+
_PyEval_FormatExcCheckArg(tstate, PyExc_UnboundLocalError,
1907+
UNBOUNDLOCAL_ERROR_MSG, name);
1908+
}
19021909
ERROR_IF(true);
19031910
}
19041911
_PyStackRef tmp = GETLOCAL(oparg);

Python/executor_cases.c.h

Lines changed: 35 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/generated_cases.c.h

Lines changed: 35 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)