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

Stephen J. Turnbull stephen at xemacs.org
Sat Oct 12 04:47:57 CEST 2013


Nick Coghlan writes:

 > (RDM is also right that the exception still has the effect of
 > terminating the block early, but I view names as mnemonics rather
 > than necessarily 100% accurate descriptions of things).

This is just way too ambiguous for my taste.  I can't help reading

    with contextlib.ignore(ExceptionIDontFeelLikeHandlingProperly):
        stmt1
        stmt2
        stmt3

as

    try:
        stmt1
    except ExceptionIDontFeelLikeHandlingProperly:
        pass
    try:
        stmt2
    except ExceptionIDontFeelLikeHandlingProperly:
        pass
    try:
        stmt3
    except ExceptionIDontFeelLikeHandlingProperly:
        pass

rather than

    try:
        stmt1
        stmt2
        stmt3
    except ExceptionIDontFeelLikeHandlingProperly:
        pass

It just feels like the exception should be suppressed at some level
"lower" than stmtN, so stmtN fails but the suite continues.  How about

    with contextlib.break_on(ExceptionIDontFeelLikeHandlingProperly):
        stmt1
        stmt2
        stmt3

This is not 100% accurate Pythonically (there's no loop to break
here), but it does describe what the context manager does more
accurately, and it does effectively break out of the 'with' control
structure.



More information about the Python-Dev mailing list