On Fri, 27 Nov 2020 07:50:20 +1100 Steven D'Aprano <steve@pearwood.info> wrote:
On Thu, Nov 26, 2020 at 02:15:50PM -0500, nate lust wrote:
It would be convenient if you could mark in source code that you intended a resource to be "moved" and any further access through other bindings are not what was intended. This would help catch logic bugs during type checking, instead of hitting this issue at runtime.
I can't help but feel that if your code relies on the concept of "moving" an object, your concept is already at odds with Python's object and execution model.
Lots of code probably relies on it. As soon as you wrap a file-like object in a higher-level construct, for example a ZipFile, you'd better not do anything again with the file-like object (*) but let the ZipFile be the sole owner of that object. Same if you pass an open socket to a HTTP library, or anything similar. (*) except closing it at the end, perhaps. Regards Antoine.