Delete module-level loop variables when no longer needed #90723
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
assignee = None closed_at = None created_at = <Date 2022-01-28.16:47:31.465> labels = ['type-bug', 'library', '3.9', '3.10', '3.11'] title = 'Delete module-level loop variables when no longer needed' updated_at = <Date 2022-02-03.09:20:22.802> user = 'https://github.com/sobolevn'
activity = <Date 2022-02-03.09:20:22.802> actor = 'serhiy.storchaka' assignee = 'none' closed = False closed_date = None closer = None components = ['Library (Lib)'] creation = <Date 2022-01-28.16:47:31.465> creator = 'sobolevn' dependencies =  files =  hgrepos =  issue_num = 46565 keywords = ['patch'] message_count = 6.0 messages = ['412006', '412017', '412056', '412059', '412065', '412429'] nosy_count = 5.0 nosy_names = ['terry.reedy', 'zach.ware', 'serhiy.storchaka', 'sobolevn', 'AlexWaygood'] pr_nums = ['30993'] priority = 'normal' resolution = None stage = 'patch review' status = 'open' superseder = None type = 'behavior' url = 'https://bugs.python.org/issue46565' versions = ['Python 3.9', 'Python 3.10', 'Python 3.11']
The text was updated successfully, but these errors were encountered:
Some variables created as
I wrote a simple
Here's what I got:
I think, that we need to remove these names. Why?
I think that adding
PR is on its way!
+1 for the proposed PR. Loop variables leaking into the global namespace creates an extra burden for typeshed when we have to wade through a long list of objects that our tests report are present at runtime but not in the typeshed stubs. It's not the end of the world, but it takes time, and is annoying.
As Nikita explains, these leaky variables also make the output of
The fix isn't hard, and shouldn't, in my opinion, be particularly controversial.
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.
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.
Thanks for the better wording, Terry!
Just to be clear: it sure is! But, sometimes we don't want to polute a global namespace with this variable. A common practice across CPython's source is to use
Interesting idea! But, I think that this is an orthogonal non-blocking task, which might be much harder compared to this one :)
I will add this to my backlog.
Good starting point, agreed!
I agree that the typeshed issue is less important than the output of dir() and help(). I also agree that we shouldn't make a fetish of typing.
However, I see the typeshed issue less as an issue specific to typing, and more as an example that illustrates a general problem third-party tools have. For example, having these temporary variables leak into global namespaces also makes IDE autocompletion less valuable, and makes life harder for tools that auto-generate documentation.
Perhaps a PEP-8 revision might be warranted in due course — but in the meantime, are there any downsides to this proposed change? I believe we have pointed out several upsides.
I don't see this as a style issue first and foremost: the PR is attempting to solve a genuine problem for some end-users of Python. It is not simply making cosmetic changes.