-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
str.format_map() silences exceptions in __getitem__ #75161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Example: class BrokenMapping:
def __getitem__(self, key):
1/0
# this silences the ZeroDivisionError and raises KeyError('world')
'hello {world}'.format_map(BrokenMapping()) I have tried this on several different CPython versions on Ubuntu 14.04 |
Yet one consequence: this swallows KeyboardInterrupt and converts it to KeyError. |
While KeyboardInterrupt and ZeroDivisionError are easy to understand, IndexError converted to KeyError doesn't look like a major bug. So I'm not sure about fixing Python 3.5 and 3.6. Maybe it's ok because this function is rarely used and exceptions are not "expected": I hardly imagine a code explicitly catching KeyError to do something on format_map() error. In short, my vote for backport is +0 :-) |
I'm -0 on a backport. The new behavior is more correct, but I don't like changing the exception type in a micro release. |
What are your thoughts about backporting this Raymond? |
For Python 3.5 and 3.6, would it make sense to modify the code to pass though BaseException, but replace all other exceptions with KeyError? It would be a compromise between doing nothing and fixing the bug :-) |
+0 On the one hand, this can be considered a bug fix. On the other hand, I would suspect that no code that is currently working would benefit. |
I think all exceptions should be passed through. Things like >>> [] in {}
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unhashable type: 'list' |
Oops, I forgot to mention that I have no thoughts about backporting |
I'm -0 on the backport since as Raymond and Eric pointed out it won't benefit currently working code and I personally don't like changing what exception is raised in a bugfix release. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: