Commits

Victor Stinner committed 01f3395 Merge

(Merge 3.3) Close #17702: On error, os.environb now removes suppress the except
context when raising a new KeyError with the original key.

Comments (0)

Files changed (3)

             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):
             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:

Lib/test/test_os.py

         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()."""
 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