From 2229cffa00c908960de4a2d973a7d33c542b96b9 Mon Sep 17 00:00:00 2001 From: Irit Katriel Date: Mon, 22 Mar 2021 17:46:17 +0000 Subject: [PATCH 1/7] bpo-17792: more accurate error message for UnboundLocalError --- Python/ceval.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Python/ceval.c b/Python/ceval.c index 3bbcfe9c237d88..e7275c2bd232c3 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -101,7 +101,8 @@ 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" + "local variable '%.200s' referenced before assignment" \ + " or after deletion" #define UNBOUNDFREE_ERROR_MSG \ "free variable '%.200s' referenced before assignment" \ " in enclosing scope" From 7826eaf62db5a8fef5abbc170d44ddb4cc820435 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Mon, 22 Mar 2021 17:50:32 +0000 Subject: [PATCH 2/7] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Core and Builtins/2021-03-22-17-50-30.bpo-17792._zssjS.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2021-03-22-17-50-30.bpo-17792._zssjS.rst 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..31359f9abd5778 --- /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 message for UnboundLocalError: local variable could have been referenced after deletion, rather than before assignment. \ No newline at end of file From d0c3650e215cdbf4e043fe234bb661908339cf0e Mon Sep 17 00:00:00 2001 From: Irit Katriel Date: Tue, 1 Jun 2021 00:00:39 +0100 Subject: [PATCH 3/7] update per review discussion. Changed UNBOUNDFREE_ERROR_MSG as well --- Python/ceval.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Python/ceval.c b/Python/ceval.c index e7275c2bd232c3..84b7c0693f3b04 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -101,11 +101,9 @@ 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" \ - " or after deletion" + "accessed local variable '%.200s' where it is not associated with a value" #define UNBOUNDFREE_ERROR_MSG \ - "free variable '%.200s' referenced before assignment" \ - " in enclosing scope" + "accessed free variable '%.200s' where it is not associated with a value" /* Dynamic execution profile */ #ifdef DYNAMIC_EXECUTION_PROFILE From 658cab1947666bf1a9c14e66fd024a4ee07d071b Mon Sep 17 00:00:00 2001 From: Irit Katriel <1055913+iritkatriel@users.noreply.github.com> Date: Tue, 1 Jun 2021 00:14:11 +0100 Subject: [PATCH 4/7] update news file to add the free vars change as --- .../Core and Builtins/2021-03-22-17-50-30.bpo-17792._zssjS.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 31359f9abd5778..768cbf14efad9c 100644 --- 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 @@ -1 +1 @@ -More accurate error message for UnboundLocalError: local variable could have been referenced after deletion, rather than before assignment. \ No newline at end of file +More accurate error messages for access of unbound locals or free vars. From 86ace25d67a7bcfc75b36cbf5e3fb2b1510aaa96 Mon Sep 17 00:00:00 2001 From: Irit Katriel Date: Tue, 1 Jun 2021 00:31:19 +0100 Subject: [PATCH 5/7] added back 'in enclosing scope' for free var --- Python/ceval.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Python/ceval.c b/Python/ceval.c index 84b7c0693f3b04..7bc92e339db2da 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -103,7 +103,8 @@ static int get_exception_handler(PyCodeObject *, int, int*, int*, int*); #define UNBOUNDLOCAL_ERROR_MSG \ "accessed local variable '%.200s' where it is not associated with a value" #define UNBOUNDFREE_ERROR_MSG \ - "accessed free variable '%.200s' where it is not associated with a value" + "accessed free variable '%.200s' where it is not associated with a" \ + " value in enclosing scope" /* Dynamic execution profile */ #ifdef DYNAMIC_EXECUTION_PROFILE From 1a146a4e39f23ed947e20ebcd6e9752891ef7fc7 Mon Sep 17 00:00:00 2001 From: Irit Katriel <1055913+iritkatriel@users.noreply.github.com> Date: Tue, 1 Jun 2021 12:46:42 +0100 Subject: [PATCH 6/7] accessed --> cannot access Co-authored-by: Victor Stinner --- Python/ceval.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/ceval.c b/Python/ceval.c index 7bc92e339db2da..c0b052e3bcbf73 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -101,7 +101,7 @@ static int get_exception_handler(PyCodeObject *, int, int*, int*, int*); #define NAME_ERROR_MSG \ "name '%.200s' is not defined" #define UNBOUNDLOCAL_ERROR_MSG \ - "accessed local variable '%.200s' where it is not associated with a value" + "cannot access local variable '%s' where it is not associated with a value" #define UNBOUNDFREE_ERROR_MSG \ "accessed free variable '%.200s' where it is not associated with a" \ " value in enclosing scope" From ea9857c33c6f0aa86ce8855113ceb69d99fbd403 Mon Sep 17 00:00:00 2001 From: Irit Katriel <1055913+iritkatriel@users.noreply.github.com> Date: Tue, 1 Jun 2021 12:46:55 +0100 Subject: [PATCH 7/7] accessed --> cannot access Co-authored-by: Victor Stinner --- Python/ceval.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/ceval.c b/Python/ceval.c index c0b052e3bcbf73..4dff7bd2df9834 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -103,7 +103,7 @@ static int get_exception_handler(PyCodeObject *, int, int*, int*, int*); #define UNBOUNDLOCAL_ERROR_MSG \ "cannot access local variable '%s' where it is not associated with a value" #define UNBOUNDFREE_ERROR_MSG \ - "accessed free variable '%.200s' where it is not associated with a" \ + "cannot access free variable '%s' where it is not associated with a" \ " value in enclosing scope" /* Dynamic execution profile */