Skip to content

bpo-29593: Improve UnboundLocalError message.#141

Closed
Carreau wants to merge 1 commit intopython:masterfrom
Carreau:unboundlocal
Closed

bpo-29593: Improve UnboundLocalError message.#141
Carreau wants to merge 1 commit intopython:masterfrom
Carreau:unboundlocal

Conversation

@Carreau
Copy link
Copy Markdown
Contributor

@Carreau Carreau commented Feb 17, 2017

Raymond Hettinger reported during PyCon Canada 2016 Keynote (~20m30 sec)
that unbound local error message was inaccurate, it state that :

local variable 'xxx' referenced before assignment

Though it can be assigned and deleted.

for a toy example:

   def foo():
      x = 1
      del x
      print(x)

   foo()

Do the same for free variable.

def multiplier(n):
def multiply(x):
    return x * n
del n
return multiply

Raymond Hettinger reported during PyCon Canada 2016 Keynote (~20m30 sec)
That unbound local error message was inaccurate, it state that :

> local variable 'xxx' referenced before assignment

Though it can be assigned and deleted.

    for a toy example:

       def foo():
          x = 1
          del x
          print(x)

       foo()

Do the same for free variable.

    def multiplier(n):
	def multiply(x):
	    return x * n
	del n
	return multiply
@ned-deily
Copy link
Copy Markdown
Member

You should create an issue on bugs.python.org for this if it doesn't already exist and mention it here. Comments on pull requests are just for code review of existing issues on b.p.o.

@Carreau Carreau changed the title Improve UnboundLocalError message. bpo-29593: Improve UnboundLocalError message. Feb 17, 2017
@Carreau
Copy link
Copy Markdown
Contributor Author

Carreau commented Feb 17, 2017

You should create an issue on bugs.python.org for this if it doesn't already exist and mention it here. Comments on pull requests are just for code review of existing issues on b.p.o.

Thanks, done. http://bugs.python.org/issue29593

@serhiy-storchaka serhiy-storchaka added the type-feature A feature request or enhancement label Feb 18, 2017
@Carreau Carreau closed this Aug 17, 2017
akruis pushed a commit to akruis/cpython that referenced this pull request Nov 7, 2017
Call Py_DECREF(frame) with the right recursion_depth.
akruis pushed a commit to akruis/cpython that referenced this pull request Mar 25, 2018
Call Py_DECREF(frame) with the right recursion_depth. Add a
changelog entry. The actual fix was part of commit cfd51a5.
akruis pushed a commit to akruis/cpython that referenced this pull request Jun 19, 2018
Call Py_DECREF(frame) with the right recursion_depth.

(cherry picked from commit e520032)
@Carreau Carreau deleted the unboundlocal branch October 20, 2025 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants