Hi Mark

Thank you for your answering

>
> I don't think this statement contradicts the intent of EAFP.

I got it :)

>> Personally, I prefer not to use exception for such cases.
>
> My instinct is the same, but EAFP does seem to be the python way. There
> are times I can tolerate the EAFP approach but, even then, I generally
> think LBYL is cleaner.

ok, so i'm worrying about the case one reviewer says to use LBYL, and
the other mentioning EAFP.
so it is great if we could some some criteria for this.

> I can live with something like this:
>
>   try:
>       return obj.foo
>   except AttributeError:
>       pass
>
> but this is obviously broken:
>
>   try:
>       return self.do_something(obj.foo)
>   except AttributeError:
>       pass
>
> since AttributeError will mask a typo with the do_something() call or an
> AttributeError raised from inside do_something()
>
> But I fail to see what's wrong with this:
>
>   if hasattr(obj, 'foo'):
>       return obj.foo
>
> Cheers,
> Mark.
>
>
> _______________________________________________
> OpenStack-dev mailing list
> OpenStack-dev@lists.openstack.org
> http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev

_______________________________________________
OpenStack-dev mailing list
OpenStack-dev@lists.openstack.org
http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev

Reply via email to