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.

But putting that aside, is this is even technically possible? Can type 
checkers track the "owner" of a resource in this way?


    obj = {}      # obj is owned by this code block
    process(obj)  # still owned by this block
    print(obj)    # so this is okay
    capture(obj)  # but now ownership is stolen by capture()
    print(obj)    # and this is a type-error (?!)


Maybe I'm just not familiar enough with the type-checking state of art, 
but I would be amazed if this was possible.

By the way, I have intentionally used the term "stolen" rather than 
"taken" or "transfered to" with respect to moving ownership of `obj`. At 
the caller's site, there is no obvious difference between the calls to 
process() which doesn't move obj, and capture() which does.

Any innocuous-looking function could "move" ownership, with *or without* 
the knowledge of the caller. It's true that the Python interpreter 
itself has no concept of "ownership" in this sense, but to the degree 
that the coder cares about such ownership, having it moved without their 
knowledge and consent is surely "theft" :-)


-- 
Steve
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/MNWGVXD2HSG7JY673PWX63VCFVPCXDZW/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to