[Python-Dev] Proposed changes to PEP 343

Nick Coghlan ncoghlan at gmail.com
Sat Oct 8 01:31:48 CEST 2005

Fredrik Lundh wrote:
> Nick Coghlan wrote:
>>However, requiring a decorator to get a slot to work right looks pretty ugly
>>to me, too.
> the whole concept might be perfectly fine on the "this construct corre-
> sponds to this code" level, but if you immediately end up with things that
> are not what they seem, and names that don't mean what the say, either
> the design or the description of it needs work.
>  ("yes, I know you can use this class to manage the context, but it's not
> really a context manager, because it's that method that's a manager, not
> the class itself.  yes, all the information that belongs to the context are
> managed by the class, but that doesn't make... oh, shut up and read the
> PEP")

Heh. OK, my current inclinitation is to make the new paragraph at the end of 
the "Generator Decorator" section read like this:

4. Add a paragraph to the end of the "Generator Decorator" section:

      If a generator is used to write a context's __with__ method, then
    Python's type machinery will automatically take care of applying this
    decorator. This means that it is just as easy to write a generator-based
    context manager for a context as it is to write a generator-based iterator
    for an iterable (see the decimal.Context example below).

And then update the decimal.Context example to remove the @contextmanager 


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-Dev mailing list