[Python-Dev] PEP 463: Exception-catching expressions

Chris Angelico rosuav at gmail.com
Sat Feb 22 11:09:07 CET 2014


On Sat, Feb 22, 2014 at 8:58 PM, Antoine Pitrou <solipsis at pitrou.net> wrote:
> On Sat, 22 Feb 2014 20:29:27 +1100
> Chris Angelico <rosuav at gmail.com> wrote:
>>
>> Which means that, fundamentally, EAFP is the way to do it. So if PEP
>> 463 expressions had existed from the beginning, hasattr() probably
>> wouldn't have been written - people would just use an
>> except-expression instead.
>
> Really? hasattr() is much easier to write than the corresponding
> except-expression.

But would it be sufficiently easier to justify the creation of a
built-in? Imagine this were the other way around: we have
except-expressions, but we don't have hasattr. Now someone comes onto
python-ideas and says, "Wouldn't it be nice if we had a hasattr()
function to tell us whether something has an attribute or not".
Considering that hasattr can be easily implemented using an
except-expression, it would be unlikely to be considered worthy of a
built-in.

ChrisA


More information about the Python-Dev mailing list