Author walker.hale.iv
Recipients docs@python, martin.panter, r.david.murray, walker.hale.iv
Date 2016-10-26.03:13:37
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Clarifying the documentation regarding the __enter__ method eliminates the need for further discussion on this point regarding pop_all(), which was really just the motivating use case.

That leaves the question of the most readable documentation change that accomplishes the result — some point between verbose and terse that minimizes the time required to comprehend the material.

My problem with the language "ExitStack instances return themselves when used in a with statement" is that it only specifies the return value of the __enter__ method but leaves open the question of whether the __enter__ method is doing anything else, particularly in the case of an ExitStack that is already loaded with context managers. How does a reader know that the __enter__ method of a loaded ExitStack doesn't call the __enter__ method of the the context managers inside? The documentation elsewhere provides strong evidence against this, but nothing that makes the point explicit. The reader is left with an exercise in deduction.

How about replacing my previous wording with: "The __enter__ method has no behavior besides returning the ExitStack instance?"

(I feel a little dirty using that language, since it might tie the hands of future developers. The truly correct wording would be "The __enter__ method is idempotent and behaves as if the only thing it does is return the ExitStack instance." That more verbose description gives future developers the freedom to do weird JIT optimizations and caching as needed, but who has the patience for such legally exhaustive specification?)

Placing the wording where I did — at the end of the class discussion and prior to the new methods — prevents this point from obscuring the main purpose of ExitStack while still leaving a place for such messy but important details. (Amazing the thought that goes into documenting a two-line method.)
Date User Action Args
2016-10-26 03:13:38walker.hale.ivsetrecipients: + walker.hale.iv, r.david.murray, docs@python, martin.panter
2016-10-26 03:13:38walker.hale.ivsetmessageid: <>
2016-10-26 03:13:38walker.hale.ivlinkissue28516 messages
2016-10-26 03:13:37walker.hale.ivcreate