mirror of
https://github.com/python/cpython.git
synced 2025-10-03 05:35:59 +00:00
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:
parent
f1e0273023
commit
0c2dd0c0a9
3 changed files with 8 additions and 2 deletions
|
@ -673,7 +673,7 @@ class _Environ(MutableMapping):
|
||||||
value = self._data[self.encodekey(key)]
|
value = self._data[self.encodekey(key)]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
# raise KeyError with the original key value
|
# raise KeyError with the original key value
|
||||||
raise KeyError(key)
|
raise KeyError(key) from None
|
||||||
return self.decodevalue(value)
|
return self.decodevalue(value)
|
||||||
|
|
||||||
def __setitem__(self, key, value):
|
def __setitem__(self, key, value):
|
||||||
|
@ -689,7 +689,7 @@ class _Environ(MutableMapping):
|
||||||
del self._data[encodedkey]
|
del self._data[encodedkey]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
# raise KeyError with the original key value
|
# raise KeyError with the original key value
|
||||||
raise KeyError(key)
|
raise KeyError(key) from None
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
for key in self._data:
|
for key in self._data:
|
||||||
|
|
|
@ -644,10 +644,13 @@ class EnvironTests(mapping_tests.BasicTestMappingProtocol):
|
||||||
with self.assertRaises(KeyError) as cm:
|
with self.assertRaises(KeyError) as cm:
|
||||||
os.environ[missing]
|
os.environ[missing]
|
||||||
self.assertIs(cm.exception.args[0], missing)
|
self.assertIs(cm.exception.args[0], missing)
|
||||||
|
self.assertTrue(cm.exception.__suppress_context__)
|
||||||
|
|
||||||
with self.assertRaises(KeyError) as cm:
|
with self.assertRaises(KeyError) as cm:
|
||||||
del os.environ[missing]
|
del os.environ[missing]
|
||||||
self.assertIs(cm.exception.args[0], missing)
|
self.assertIs(cm.exception.args[0], missing)
|
||||||
|
self.assertTrue(cm.exception.__suppress_context__)
|
||||||
|
|
||||||
|
|
||||||
class WalkTests(unittest.TestCase):
|
class WalkTests(unittest.TestCase):
|
||||||
"""Tests for os.walk()."""
|
"""Tests for os.walk()."""
|
||||||
|
|
|
@ -66,6 +66,9 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #17702: On error, os.environb now removes suppress the except context
|
||||||
|
when raising a new KeyError with the original key.
|
||||||
|
|
||||||
- Issue #18755: Fixed the loader used in imp to allow get_data() to be called
|
- Issue #18755: Fixed the loader used in imp to allow get_data() to be called
|
||||||
multiple times.
|
multiple times.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue