summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2013-08-23 19:23:42 +0200
committerVictor Stinner <victor.stinner@gmail.com>2013-08-23 19:23:42 +0200
commit643ea2dd1185d2dfd60f297410f49f78a4ae8015 (patch)
tree5e4ffe30a57739adb60da1cfcff0ac9f3eddf810
parentd6b91574b271df45c051e7a99fe06e848b223a1d (diff)
parent7549e8f6529ab47e84253442819f40e4f092b679 (diff)
downloadcpython-643ea2dd1185d2dfd60f297410f49f78a4ae8015.tar.gz
(Merge 3.3) Close #17702: On error, os.environb now removes suppress the except
context when raising a new KeyError with the original key.
-rw-r--r--Lib/os.py4
-rw-r--r--Lib/test/test_os.py3
-rw-r--r--Misc/NEWS3
3 files changed, 8 insertions, 2 deletions
diff --git a/Lib/os.py b/Lib/os.py
index 96720e41ef..5fde36075c 100644
--- a/Lib/os.py
+++ b/Lib/os.py
@@ -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:
diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py
index b7796b5607..a4be0bb1a6 100644
--- a/Lib/test/test_os.py
+++ b/Lib/test/test_os.py
@@ -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()."""
diff --git a/Misc/NEWS b/Misc/NEWS
index 7b62d16e07..431674abbd 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -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