[Python-checkins] cpython (merge 3.3 -> default): #17572: merge with 3.3.

ezio.melotti python-checkins at python.org
Thu Apr 4 01:16:43 CEST 2013


http://hg.python.org/cpython/rev/d408c9bd4bf7
changeset: 83092:d408c9bd4bf7
parent: 83089:a8a238cf59c7
parent: 83091:3203e083aa7b
user: Ezio Melotti <ezio.melotti at gmail.com>
date: Thu Apr 04 02:16:27 2013 +0300
summary:
 #17572: merge with 3.3.
files:
 Lib/_strptime.py | 2 +-
 Lib/test/test_strptime.py | 6 ++++++
 Lib/test/test_time.py | 6 ++++++
 Misc/NEWS | 3 +++
 4 files changed, 16 insertions(+), 1 deletions(-)
diff --git a/Lib/_strptime.py b/Lib/_strptime.py
--- a/Lib/_strptime.py
+++ b/Lib/_strptime.py
@@ -326,7 +326,7 @@
 bad_directive = "%"
 del err
 raise ValueError("'%s' is a bad directive in format '%s'" %
- (bad_directive, format))
+ (bad_directive, format)) from None
 # IndexError only occurs when the format string is "%"
 except IndexError:
 raise ValueError("stray %% in format '%s'" % format)
diff --git a/Lib/test/test_strptime.py b/Lib/test/test_strptime.py
--- a/Lib/test/test_strptime.py
+++ b/Lib/test/test_strptime.py
@@ -218,6 +218,12 @@
 else:
 self.fail("'%s' did not raise ValueError" % bad_format)
 
+ def test_strptime_exception_context(self):
+ # check that this doesn't chain exceptions needlessly (see #17572)
+ with self.assertRaises(ValueError) as e:
+ _strptime._strptime_time('', '%D')
+ self.assertIs(e.exception.__suppress_context__, True)
+
 def test_unconverteddata(self):
 # Check ValueError is raised when there is unconverted data
 self.assertRaises(ValueError, _strptime._strptime_time, "10 12", "%m")
diff --git a/Lib/test/test_time.py b/Lib/test/test_time.py
--- a/Lib/test/test_time.py
+++ b/Lib/test/test_time.py
@@ -193,6 +193,12 @@
 self.assertRaises(TypeError, time.strptime, b'2009', "%Y")
 self.assertRaises(TypeError, time.strptime, '2009', b'%Y')
 
+ def test_strptime_exception_context(self):
+ # check that this doesn't chain exceptions needlessly (see #17572)
+ with self.assertRaises(ValueError) as e:
+ time.strptime('', '%D')
+ self.assertIs(e.exception.__suppress_context__, True)
+
 def test_asctime(self):
 time.asctime(time.gmtime(self.t))
 
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -304,6 +304,9 @@
 Library
 -------
 
+- Issue #17572: Avoid chained exceptions while passing bad directives to
+ time.strptime(). Initial patch by Claudiu Popa.
+
 - Issue #14254: IDLE now handles readline correctly across shell restarts.
 
 - Issue #17614: IDLE no longer raises exception when quickly closing a file.
-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /