[Python-ideas] Retrying EAFP without DRY
jimjjewett at gmail.com
Wed Jan 25 16:32:35 CET 2012
On Mon, Jan 23, 2012 at 10:18 PM, Stephen J. Turnbull
<stephen at xemacs.org> wrote:
> Jim Jewett writes:
> > So it doesn't seem like a loop because you hope to do it only once?
> With s/hope/expect/, that hits the nail on the head.
> I don't think syntax can express that cleanly, but I can't help
> thinking it's of good thing if somebody like Mike tries to find a way.
> He might succeed!
I have often wanted a clean way to indicate "This branch can happen,
but isn't normal." (Well, besides a comment that might be seen as
condescending if it is *obviously* an edge case.) The retry proposal
is just specializing that for when the weird branch includes a loop.
Right now, the best I can do is hope that the special case (and
possibly the normal case, if it is repeated) can be factored out, so
that I can write
if not doit(args):
if not doit(tweak1(args)):
if not doit(tweak2(args)):
# Alternatively, make this suite much longer, so that it is
# "obviously" the main point of the function.
That said, I've wanted unusual-case annotation more when I thought the
compiler might use the information. Without compiler support, I'm not
sure how much takeup there would be for the resulting
More information about the Python-ideas