[docs] [issue18478] Class bodies: when does a name become local?
Terry J. Reedy
report at bugs.python.org
Wed Jul 17 01:39:14 CEST 2013
New submission from Terry J. Reedy:
says "The following are blocks: ... a class definition." and
"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 is definitely true for functions, but not for classes:
foo = 'bar'
foo = foo
This is the same for 3.3 and 2.7 with and without '(object)' added. Unless the code is considered to be buggy (probably since forever), the doc should be modified to change 'code block' to 'function code block' or maybe 'module or function code block'. (At near as I can think, the statement is true for modules, but only because globals() == locals(), so that part of the issue does not arise.)
assignee: docs at python
nosy: docs at python, terry.reedy
stage: needs patch
title: Class bodies: when does a name become local?
versions: Python 2.7, Python 3.3, Python 3.4
Python tracker <report at bugs.python.org>
More information about the docs