On 10/15/2012 03:13 PM, Ole Laursen wrote:
On Friday, October 12, 2012 3:35:53 PM UTC+2, Chris Wilson wrote:
I'm strongly in favour of a simple, obvious way to do the common
thing,
which is to return None if the object doesn't exist, instead of
throwing
an exception. My preferred method names would be .nget(),
.get_or_none()
or .first().
IMHO the fact that we have all these inventive solutions is ample
proof that people do come across this problem and find it annoying. I
just found out today that there's a somewhat related .latest().
Anyway, without a sponsor with commit access I guess this is dead, so
I'll shut up now. Thank you for your time.
For the record, I still do like this idea, specifically .get_or_none().
It seems there is significant support for this idea. I do think this
method is Pythonic. There are cases where no match from get() isn't
exceptional, and in such cases try-except just feels wrong.
The counter argument is that this is API bloat, and this will set an
example for more API bloat.
In the end this is a decision with almost no technical considerations
and a lot of "good taste" considerations. So, this seems like BDFL area.
If there are no signs from BDFL that .get_or_none() is acceptable, then
lets bury this one. If it is acceptable, then I am willing to do all the
work to get this committed.
- Anssi
--
You received this message because you are subscribed to the Google Groups "Django
developers" group.
To post to this group, send email to django-developers@googlegroups.com.
To unsubscribe from this group, send email to
django-developers+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/django-developers?hl=en.