[Python-ideas] With expressions

Steven D'Aprano steve at pearwood.info
Sat Aug 4 03:43:33 EDT 2018


On Fri, Aug 03, 2018 at 06:57:40PM -0500, Abe Dillon wrote:

> tmp = None
> with suppress(AttributeError):
>     tmp = person.name[0]
> initial = tmp
> 
> Then it would solve many of the common use cases for the None-aware
> operators proposed in PEP 505

No it would not. The None-aware operators are not about suppressing 
AttributeError, please stop suggesting that it is. If you want to 
propose a general exception suppressing mechanism (aside from the 
existing try...except statement) then propose it as an independent PEP.

Even if we had a general purpose exception-suppressing expression, it 
wouldn't meet the functional requirements for PEP 505. It would do too 
much, like offering somebody a bulldozer when all we want is a dustpan 
and broom.



> especially if we made it easy to filter out
> None-specific errors:
> 
> class NoneError(BaseException):
>     pass
> 
> class NoneAttributeError(AttributeError, NoneError):
>     pass

They're not None specific. Any object can raise them.



-- 
Steve


More information about the Python-ideas mailing list