mirror of https://github.com/python/cpython
(Merge 3.3) Close #17702: On error, os.environb now removes suppress the except
context when raising a new KeyError with the original key.
This commit is contained in:
commit
a93c6db68b
|
@ -648,7 +648,7 @@ class _Environ(MutableMapping):
|
|||
value = self._data[self.encodekey(key)]
|
||||
except KeyError:
|
||||
# raise KeyError with the original key value
|
||||
raise KeyError(key)
|
||||
raise KeyError(key) from None
|
||||
return self.decodevalue(value)
|
||||
|
||||
def __setitem__(self, key, value):
|
||||
|
@ -664,7 +664,7 @@ class _Environ(MutableMapping):
|
|||
del self._data[encodedkey]
|
||||
except KeyError:
|
||||
# raise KeyError with the original key value
|
||||
raise KeyError(key)
|
||||
raise KeyError(key) from None
|
||||
|
||||
def __iter__(self):
|
||||
for key in self._data:
|
||||
|
|
|
@ -646,10 +646,13 @@ class EnvironTests(mapping_tests.BasicTestMappingProtocol):
|
|||
with self.assertRaises(KeyError) as cm:
|
||||
os.environ[missing]
|
||||
self.assertIs(cm.exception.args[0], missing)
|
||||
self.assertTrue(cm.exception.__suppress_context__)
|
||||
|
||||
with self.assertRaises(KeyError) as cm:
|
||||
del os.environ[missing]
|
||||
self.assertIs(cm.exception.args[0], missing)
|
||||
self.assertTrue(cm.exception.__suppress_context__)
|
||||
|
||||
|
||||
class WalkTests(unittest.TestCase):
|
||||
"""Tests for os.walk()."""
|
||||
|
|
|
@ -38,6 +38,9 @@ Core and Builtins
|
|||
Library
|
||||
-------
|
||||
|
||||
- Issue #17702: On error, os.environb now removes suppress the except context
|
||||
when raising a new KeyError with the original key.
|
||||
|
||||
- Issue #16809: Fixed some tkinter incompabilities with Tcl/Tk 8.6.
|
||||
|
||||
- Issue #16809: Tkinter's splitlist() and split() methods now accept Tcl_Obj
|
||||
|
|
Loading…
Reference in New Issue