[Python-Dev] cpython: Rename contextlib.ignored() to contextlib.ignore().

R. David Murray rdmurray at bitdance.com
Fri Oct 11 21:22:34 CEST 2013


On Fri, 11 Oct 2013 20:01:07 +0100, MRAB <python at mrabarnett.plus.com> wrote:
> On 11/10/2013 19:41, Glenn Linderman wrote:
> > On 10/11/2013 10:19 AM, Eric V. Smith wrote:
> >> On 10/11/2013 12:43 PM, Barry Warsaw wrote:
> >>> On Oct 11, 2013, at 06:27 PM, Georg Brandl wrote:
> >>>
> >>>> Maybe to fit in with other verb-like APIs used as context managers:
> >>>> it's open() not opened().
> >>> open() predates context managers, but maybe we need a new convention.
> >>>
> >>> with ignore(FileNotFoundError):
> >>>
> >>> vs
> >>>
> >>> with ignored(FileNotFoundError):
> >>>
> >>> To me anyway, the latter sounds better.
> >> I'm still -0, and maybe now -1 on the idea, mostly because it encourages
> >> an anti-pattern.
> >>
> >> But, to continue to paint the shed, shouldn't it be "ignoring", to match
> >> "closing"?
> >
> > Seriously, "with" is the wrong spelling for this using.  It should be
> >
> > while ignorning(FileNotFoundError)
> >
> > Insistence on using "with" for the anti-pattern, and proper English,
> > would require:
> >
> > with ignorance_of(FileNotFoundError)
> >
> > :)
> >
> "Ignorance" means not knowing, but we _do_ know about FileNotFoundError.
> What we want is to ignore it.

Isn't "ignore" in any form really a lie here, though?  We are not
ignoring it, we are catching it and taking an early exit out of
the with block:

    with ignore(FileNotFoundError):
        with open('f') as f:
            print("hello world")
        print("goodbye world")

This does not print anything, whereas for either intuitive meaning
I can think of for "ignoring" the error, it ought to print something.
You really can't *ignore* errors inside a with block.

This incorrect intuition is exactly why this is an anti-pattern.
'ignore' is an attractive nuisance.

This having occurred to me, I am now definitely -1.

--David


More information about the Python-Dev mailing list