Steven D'Aprano <steve+pyt...@pearwood.info> added the comment:

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.

----------
nosy: +steven.daprano
resolution:  -> not a bug
stage:  -> resolved

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue44332>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to