[Python-checkins] bpo-17792: more accurate error message for unbound variable access exceptions (GH-24976)
iritkatriel
webhook-mailer at python.org
Wed Jun 2 09:09:17 EDT 2021
https://github.com/python/cpython/commit/7b1f527d5b37dc3aa085ebbe11a1a2dd29ef210f
commit: 7b1f527d5b37dc3aa085ebbe11a1a2dd29ef210f
branch: main
author: Irit Katriel <1055913+iritkatriel at users.noreply.github.com>
committer: iritkatriel <1055913+iritkatriel at users.noreply.github.com>
date: 2021-06-02T14:09:04+01:00
summary:
bpo-17792: more accurate error message for unbound variable access exceptions (GH-24976)
files:
A Misc/NEWS.d/next/Core and Builtins/2021-03-22-17-50-30.bpo-17792._zssjS.rst
M Python/ceval.c
diff --git a/Misc/NEWS.d/next/Core and Builtins/2021-03-22-17-50-30.bpo-17792._zssjS.rst b/Misc/NEWS.d/next/Core and Builtins/2021-03-22-17-50-30.bpo-17792._zssjS.rst
new file mode 100644
index 00000000000000..768cbf14efad9c
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2021-03-22-17-50-30.bpo-17792._zssjS.rst
@@ -0,0 +1 @@
+More accurate error messages for access of unbound locals or free vars.
diff --git a/Python/ceval.c b/Python/ceval.c
index 3bbcfe9c237d88..4dff7bd2df9834 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -101,10 +101,10 @@ static int get_exception_handler(PyCodeObject *, int, int*, int*, int*);
#define NAME_ERROR_MSG \
"name '%.200s' is not defined"
#define UNBOUNDLOCAL_ERROR_MSG \
- "local variable '%.200s' referenced before assignment"
+ "cannot access local variable '%s' where it is not associated with a value"
#define UNBOUNDFREE_ERROR_MSG \
- "free variable '%.200s' referenced before assignment" \
- " in enclosing scope"
+ "cannot access free variable '%s' where it is not associated with a" \
+ " value in enclosing scope"
/* Dynamic execution profile */
#ifdef DYNAMIC_EXECUTION_PROFILE
More information about the Python-checkins
mailing list