This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author steven.daprano
Recipients deb_ctc, steven.daprano
Date 2021-06-07.05:43:31
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1623044612.05.0.220372511122.issue44332@roundup.psfhosted.org>
In-reply-to
Content
This is not a bug, it is intentional design and has been since Python 1.

You are incorrect about x consuming memory "always". If the value bound to x is in use elsewhere, deleting x will save no memory. If the value is not in use elsewhere, it will be garbage collected as soon as x goes out of scope, which will be at the end of the function.

Shifting to block-scope for for-loops has been discussed before, it is not a popular idea and I expect that most people will oppose it. You can search the Python-Ideas mailing list if you want to find out more. If you still feel strongly that this is an enhancement, as it is a major change in language behaviour it would require a PEP to be written.

https://www.python.org/dev/peps/pep-0001/

Even if the PEP was accepted, the earliest it could go into the language would be Python 3.11 or better, and that would likely require a special `__future__` import.
History
Date User Action Args
2021-06-07 05:43:32steven.dapranosetrecipients: + steven.daprano, deb_ctc
2021-06-07 05:43:32steven.dapranosetmessageid: <1623044612.05.0.220372511122.issue44332@roundup.psfhosted.org>
2021-06-07 05:43:32steven.dapranolinkissue44332 messages
2021-06-07 05:43:31steven.dapranocreate