mirror of
https://github.com/python/cpython.git
synced 2025-08-15 14:20:55 +00:00
gh-48496: Added example and link to faq for UnboundLocalError in reference (GH-93068)
(cherry picked from commit f3db68e6e6
)
Co-authored-by: Stanley <46876382+slateny@users.noreply.github.com>
This commit is contained in:
parent
1e0631e5ba
commit
1fa4c6bd1f
2 changed files with 4 additions and 0 deletions
|
@ -113,6 +113,8 @@ Yes. The coding style required for standard library modules is documented as
|
||||||
Core Language
|
Core Language
|
||||||
=============
|
=============
|
||||||
|
|
||||||
|
.. _faq-unboundlocalerror:
|
||||||
|
|
||||||
Why am I getting an UnboundLocalError when the variable has a value?
|
Why am I getting an UnboundLocalError when the variable has a value?
|
||||||
--------------------------------------------------------------------
|
--------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
@ -128,6 +128,8 @@ lead to errors when a name is used within a block before it is bound. This rule
|
||||||
is subtle. Python lacks declarations and allows name binding operations to
|
is subtle. Python lacks declarations and allows name binding operations to
|
||||||
occur anywhere within a code block. The local variables of a code block can be
|
occur anywhere within a code block. The local variables of a code block can be
|
||||||
determined by scanning the entire text of the block for name binding operations.
|
determined by scanning the entire text of the block for name binding operations.
|
||||||
|
See :ref:`the FAQ entry on UnboundLocalError <faq-unboundlocalerror>`
|
||||||
|
for examples.
|
||||||
|
|
||||||
If the :keyword:`global` statement occurs within a block, all uses of the names
|
If the :keyword:`global` statement occurs within a block, all uses of the names
|
||||||
specified in the statement refer to the bindings of those names in the top-level
|
specified in the statement refer to the bindings of those names in the top-level
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue