[Python-Dev] PEP 463: Exception-catching expressions (original) (raw)
Chris Angelico rosuav at gmail.com
Thu Mar 6 01:22:00 CET 2014
- Previous message: [Python-Dev] PEP 463: Exception-catching expressions
- Next message: [Python-Dev] PEP 463: Exception-catching expressions
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Thu, Mar 6, 2014 at 7:57 AM, Thomas Wouters <thomas at python.org> wrote:
On Thu, Feb 27, 2014 at 1:29 PM, Chris Angelico <rosuav at 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
- Previous message: [Python-Dev] PEP 463: Exception-catching expressions
- Next message: [Python-Dev] PEP 463: Exception-catching expressions
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]