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

2014年2月22日 13:28:16 -0800

On 23 February 2014 02:29, Nick Coghlan <[email protected]> wrote:
> On 22 Feb 2014 22:15, "Stephen J. Turnbull" <[email protected]> wrote:
> > Antoine Pitrou writes:
> > > Chris Angelico <[email protected]> wrote:
> > > > hasattr(x,"y") <-> (x.y or True except AttributeError: False)
> > > But it's not the same. hasattr() returns a boolean, not an arbitrary
> > > value.
> > I think he meant
> > hasattr(x,"y") <-> (x.y and True except AttributeError: False)
>
> With PEP 463, the explicit equivalent of hasattr() would be something like
> :
>
> hasattr(x,"y") <-> (bool(x.y) or True except AttributeError: False)
>
That would work, but I think I'd prefer:
hasattr(x,"y") <-> bool(x.y or True except AttributeError: False)
Makes it clearer IMO that the entire expression will always return a
boolean.
If exception expressions already existed in the language, I would think
there would be a strong argument for a library function hasattr(), but
probably not a builtin.
Tim Delaney
_______________________________________________
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to