File tree Expand file tree Collapse file tree 3 files changed +8
-2
lines changed Expand file tree Collapse file tree 3 files changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -673,7 +673,7 @@ def __getitem__(self, key):
673
673
value = self ._data [self .encodekey (key )]
674
674
except KeyError :
675
675
# raise KeyError with the original key value
676
- raise KeyError (key )
676
+ raise KeyError (key ) from None
677
677
return self .decodevalue (value )
678
678
679
679
def __setitem__ (self , key , value ):
@@ -689,7 +689,7 @@ def __delitem__(self, key):
689
689
del self ._data [encodedkey ]
690
690
except KeyError :
691
691
# raise KeyError with the original key value
692
- raise KeyError (key )
692
+ raise KeyError (key ) from None
693
693
694
694
def __iter__ (self ):
695
695
for key in self ._data :
Original file line number Diff line number Diff line change @@ -644,10 +644,13 @@ def test_key_type(self):
644
644
with self .assertRaises (KeyError ) as cm :
645
645
os .environ [missing ]
646
646
self .assertIs (cm .exception .args [0 ], missing )
647
+ self .assertTrue (cm .exception .__suppress_context__ )
647
648
648
649
with self .assertRaises (KeyError ) as cm :
649
650
del os .environ [missing ]
650
651
self .assertIs (cm .exception .args [0 ], missing )
652
+ self .assertTrue (cm .exception .__suppress_context__ )
653
+
651
654
652
655
class WalkTests (unittest .TestCase ):
653
656
"""Tests for os.walk()."""
Original file line number Diff line number Diff line change @@ -66,6 +66,9 @@ Core and Builtins
66
66
Library
67
67
-------
68
68
69
+ - Issue #17702: On error, os.environb now removes suppress the except context
70
+ when raising a new KeyError with the original key.
71
+
69
72
- Issue #18755: Fixed the loader used in imp to allow get_data() to be called
70
73
multiple times.
71
74
You can’t perform that action at this time.
0 commit comments