[Python-Dev] 'With' context documentation draft (was Re: Terminology for PEP 343 (original) (raw)

Michael Chermside mcherm at mcherm.com
Wed Jul 6 14:20:26 CEST 2005


Nick writes sample documentation:

For example, the following context manager allows prompt closure of any resource with a 'close' method (e.g. a generator or file):

@context def closing(resource): try: yield resource finally: resource.close()

Reading this I get the feeling that perhaps the decorator should be named "context_manager" not "context":

    @context_manager
    def closing(resource):
        try:
            yield resource
        finally:
            resource.close()

Does anyone else agree?

Paul Moore writes:

I also like the fact that it offers a neat 1-word name for the generator decorator, "@context".

Well, ok... does anyone else agree? I too saw this and thought "neat! a simple one-word name!". But then I started worrying that it's not defining the context, but rather the context manager. While "context manager" is a term I could easily imagine associating only with 'with' statements, "context" is too general a term... even after Python supports 'with' statements I will continue to use "context" to mean lots of different things (eg: decimal.context).

By the way, great job Nick... these docs read quite nicely.

-- Michael Chermside



More information about the Python-Dev mailing list