On Sat, Jun 29, 2013 at 10:32 PM, Terry Reedy <tjre...@udel.edu> wrote: > On 6/29/2013 5:21 PM, Ian Kelly wrote: >> Or simply an explicit declaration of scope at the beginning of the >> function definition. > > One of the reasons I switched to Python was to not have to do that, or > hardly ever. For valid code, an new declaration is hardly needed. Parameters > are locals. If the first use of another name binds it (and that includes > import, class, and def), it is local. If the first use of does not bind it, > it had better not be local (because if it is, there well be an exception). > If there are branches, each should be consistent with the others. One should > only need two readings to understand and fix unbound local errors.
In general I agree, although when reading code I would definitely prefer if the locals were declared. On a related note, I think that generator functions should in some way be explicitly marked as such in the declaration, rather than needing to scan the entire function body for a yield statement to determine whether it's a generator or not. -- http://mail.python.org/mailman/listinfo/python-list