[issue46565] Delete module-level loop variables when no longer needed

Terry J. Reedy report at bugs.python.org
Sat Jan 29 01:50:25 EST 2022


Terry J. Reedy <tjreedy at udel.edu> added the comment:

I am opposed at this time.  Leaving loop variables available is an intended feature of python.

After reading point 1, I was tempted to say that you are making a fetish of typing or making the tail wag the dog. I mention this because others might have similar reactions.  After reading points 2 and 3, I am much more favorable and would allow changes in idlelib if any were needed.  A cleaner dir and help listing affects everyone.

I changed the title to be more 'neutral'.  'Leak' is perjorative.  "we need to remove these names" is a bit misleading as it implies total removal, which is not the proposal.

As it is, the PR applies a style standard on the stdlib that is not in PEP 8.  I recommend that you start by proposing an addition to PEP-8. 
 "Unless X, global loop variables should be explicitly deleted as soon as not needed.  Or use a comprehension."  (I checked and 'loop' does not currently appear in PEP-8, and none of the 5 examples I checked could use a comprehension.)

If you do, I recommend starting with dir and help, with typing third.

You might post the idea on pydev and ask how much and what sort of discussion is needed.

----------
nosy: +terry.reedy
title: Multiple modules leak `for` loop variables into module's namespace -> Delete module-level loop variables when no longer needed

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46565>
_______________________________________


More information about the Python-bugs-list mailing list