On Thu, Mar 6, 2014 at 7:57 AM, Thomas Wouters <tho...@python.org> wrote: > On Thu, Feb 27, 2014 at 1:29 PM, Chris Angelico <ros...@gmail.com> wrote: >> >> +Had this facility existed early in Python's history, there would have >> been >> +no need to create dict.get() and related methods; > > > FWIW, after experimenting and some consideration I've come to the conclusion > that this is incorrect. 'd[k] except KeyError: default' is still much > broader than dict.get(k):
*Much* broader? You prove that it's broader, yes, but most types aren't defining __hash__ methods that can fail with KeyError. Can you show any real-world code that trips this? I'd say the broadened exception scope (or, putting it the other way, the narrowed exception scope of adding dict.get() after except-expressions had already existed) is insufficiently significant to justify adding an extra method to the dict. Since the method does exist, it will continue to be useful, but if except expressions did and dict.get() didn't, there'd have been very little justification for them. And certainly hasattr() wouldn't need to exist, since it exactly _does_ try to get the attribute and see if AttributeError is raised. ChrisA _______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com