Delaney, Timothy C (Timothy) wrote:

> Guido van Rossum wrote:
> 
>> I'd like the block statement to be defined exclusively in terms of
>> __exit__() though.
> 
> 1. If an iterator declares __exit__, it cannot be used in a for-loop.
>    For-loops do not guarantee resource cleanup.
> 
> 2. If an iterator does not declare __exit__, it cannot be used in a
> block-statement.
>    Block-statements guarantee resource cleanup.

Now some thoughts have solidified in my mind ... I'd like to define some
terminology that may be useful.

resource protocol:
    __next__
    __exit__

    Note: __iter__ is explicitly *not* required.

resource:
    An object that conforms to the resource protocol.

resource generator:
    A generator function that produces a resource.

resource usage statement/suite:
    A suite that uses a resource.

With this conceptual framework, I think the following makes sense:

- Keyword 'resource' for defining a resource generator.
- Keyword 'use' for using a resource.

e.g.

::

    resource locker (lock):
        lock.acquire()
        try:
            yield
        finally:
            lock.release()

    use locker(lock):
        # do stuff

Tim Delaney
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to