Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 04a2955

Browse files
committed
#17032: The "global" in the "NameError: global name 'x' is not defined" error message has been removed. Patch by Ram Rachum.
1 parent ee71f4a commit 04a2955

4 files changed

Lines changed: 9 additions & 7 deletions

File tree

Lib/test/test_keywordonlyarg.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,10 @@ def test_default_evaluation_order(self):
182182
with self.assertRaises(NameError) as err:
183183
def f(v=a, x=b, *, y=c, z=d):
184184
pass
185-
self.assertEqual(str(err.exception), "global name 'b' is not defined")
185+
self.assertEqual(str(err.exception), "name 'b' is not defined")
186186
with self.assertRaises(NameError) as err:
187187
f = lambda v=a, x=b, *, y=c, z=d: None
188-
self.assertEqual(str(err.exception), "global name 'b' is not defined")
188+
self.assertEqual(str(err.exception), "name 'b' is not defined")
189189

190190

191191
def test_main():

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,7 @@ Fernando Pérez
969969
Pierre Quentel
970970
Brian Quinlan
971971
Anders Qvist
972+
Ram Rachum
972973
Jérôme Radix
973974
Burton Radons
974975
Jeff Ramnani

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ What's New in Python 3.4.0 Alpha 1?
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #17032: The "global" in the "NameError: global name 'x' is not defined"
14+
error message has been removed. Patch by Ram Rachum.
15+
1316
- Issue #17223: array module: Fix a crasher when converting an array containing
1417
invalid characters (outside range [U+0000; U+10ffff]) to Unicode:
1518
repr(array), str(array) and array.tounicode(). Patch written by Manuel Jacob.

Python/ceval.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,6 @@ static PyObject * special_lookup(PyObject *, _Py_Identifier *);
142142

143143
#define NAME_ERROR_MSG \
144144
"name '%.200s' is not defined"
145-
#define GLOBAL_NAME_ERROR_MSG \
146-
"global name '%.200s' is not defined"
147145
#define UNBOUNDLOCAL_ERROR_MSG \
148146
"local variable '%.200s' referenced before assignment"
149147
#define UNBOUNDFREE_ERROR_MSG \
@@ -2140,7 +2138,7 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
21402138
err = PyDict_DelItem(f->f_globals, name);
21412139
if (err != 0) {
21422140
format_exc_check_arg(
2143-
PyExc_NameError, GLOBAL_NAME_ERROR_MSG, name);
2141+
PyExc_NameError, NAME_ERROR_MSG, name);
21442142
goto error;
21452143
}
21462144
DISPATCH();
@@ -2208,7 +2206,7 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
22082206
if (v == NULL) {
22092207
if (!PyErr_Occurred())
22102208
format_exc_check_arg(PyExc_NameError,
2211-
GLOBAL_NAME_ERROR_MSG, name);
2209+
NAME_ERROR_MSG, name);
22122210
goto error;
22132211
}
22142212
Py_INCREF(v);
@@ -2222,7 +2220,7 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
22222220
if (PyErr_ExceptionMatches(PyExc_KeyError))
22232221
format_exc_check_arg(
22242222
PyExc_NameError,
2225-
GLOBAL_NAME_ERROR_MSG, name);
2223+
NAME_ERROR_MSG, name);
22262224
goto error;
22272225
}
22282226
}

0 commit comments

Comments
 (0)