[Phillip J. Eby] > > with context_expression as variable: > # perform actions within a context > > The "with" statement establishes a context in which some operations are to > be performed. Often, this is a resource management context, wherein some > resource is allocated when the context is entered, and when it is > exited. Or it may be a locking context, where a lock is acquired and > released around the statements. Or it may be a computational context, > such > as a Decimal context that controls the precision of decimal > calculations. In fact, it may be any context that can be defined in terms > of behavior to be performed when the context is entered and exited. > > The object produced by 'context_expression' must have __enter_context__ > and > __exit_context__ methods, which will be invoked by the "with" statement > when the context is entered, and when it is exited for any reason (such as > by an exception, "return" statement, or other control flow statements).
This is much improved. I think we're getting close. So far, I like Nick's most recent version the best, but this is in the ballpark. The new methods names are a step in the right direction but they are butt-ugly and unfriendly. It is much cleaner looking and equally communicative to write __beginwith__ and __endwith__. Those names are clearly bookends and associated with with-suites. They are shorter, more pithy, and don't abuse underscore conventions (the current worst offenders are test___all__.py and the set module's __as_temporarily_immutable__ attribute which gives me COBOL flashbacks). [Nick Coghlan] > Based on the various discussions, the following suggests the term > "suite managers". That focuses on the fact that we're doing something > before and after the contained suite. > > The fact that they bracket a single suite seems to be the only thing > the assorted uses really have in common, and emphasising that seems to > work well. It's certainly the first case where I've been able to > easily explain what decimal.Context does (or will do) when used in a > 'with' statement. I think you're onto something. Stick with it. Your whole write-up is clear. It is the first one that doesn't look like it had to twist its metaphor into a knot. Raymond _______________________________________________ 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