Some examples for what I have in mind:

def read_and_close_file(file: Move[FileIO]):
    """ File will be closed, so we can not use after """
    file.read()
    file.close()


@dataclass
class Model:
    x: List[int]


def make_list_from_model(model: Move[Model]) -> List[int]:
    """ This is not a pure function, which is bad,
    but if we move model here and won't use it after, then it's kinda pure """
    model.x.append(1)  # x is big and we don't want to copy it, instead we just 
push another element
    return model.x


def run_thread_unsafe_process(writer: Move[BytesIO]) -> Thread:
    thread = Thread(target=thread_unsafe_process, args=(writer,))
    thread.start()
    return thread


def thread_unsafe_process(writer: BytesIO):
    while True:
        sleep(1)
        writer.write(b'Hello!')


file = open('move.py')
read_and_close_file(file)
file.read()  # Mistake, file is already closed, static analyzer cah check that

model = Model([1, 2, 3])
y = make_list_from_model(model)
print(model.x)  # Using of corrupted value, it might be unexpected for caller 
and cause some mistakes

writer = open('buffer.tmp', 'wb')
run_thread_unsafe_process(writer)
writer.write(b'world')  # mistake, can lead to data-race (in this case, two 
messages, "hello" and "world", might mix up)
_______________________________________________
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/LXMCFYIFTDXQCAN7576HPSDZRWN7EAWO/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to