Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #50758 > unrolled thread
| Started by | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| First post | 2013-07-16 19:50 -0400 |
| Last post | 2013-07-16 19:50 -0400 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Is this a bug? Terry Reedy <tjreedy@udel.edu> - 2013-07-16 19:50 -0400
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Date | 2013-07-16 19:50 -0400 |
| Subject | Re: Is this a bug? |
| Message-ID | <mailman.4782.1374018661.3114.python-list@python.org> |
On 7/16/2013 2:04 PM, Ian Kelly wrote: > The documentation appears to be wrong. It says: > > """ > If a name binding operation occurs anywhere within a code block, all > uses of the name within the block are treated as references to the > current block. This can 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 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. > """ I agree that there is a problem. http://bugs.python.org/issue18478 > But this only applies to function blocks, not the general case. In > general, I believe it is more accurate to say that a variable is local > to the block if its name is found in the locals() dict. That is not true for functions, where names are classified as local *before* being added to the locals dict. (Actually, names are usually not added to the locals dict until locals() is called to update it). It would be better to say that names are local if found in the local namespace, and consider that names are added to a function local namespace (which is *not* the local() dict) when classified (before being bound), but otherwise only when bound. That normally > won't be true until the variable has been bound. Any references prior > to that will look for a global variable. At module scope, globals() == locals(). But feel free to suggest a different fix for the issue than I did. -- Terry Jan Reedy
Back to top | Article view | comp.lang.python
csiph-web