mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
#17572: merge with 3.3.
This commit is contained in:
commit
d57f047665
4 changed files with 16 additions and 1 deletions
|
@ -326,7 +326,7 @@ def _strptime(data_string, format="%a %b %d %H:%M:%S %Y"):
|
||||||
bad_directive = "%"
|
bad_directive = "%"
|
||||||
del err
|
del err
|
||||||
raise ValueError("'%s' is a bad directive in format '%s'" %
|
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 "%"
|
# IndexError only occurs when the format string is "%"
|
||||||
except IndexError:
|
except IndexError:
|
||||||
raise ValueError("stray %% in format '%s'" % format)
|
raise ValueError("stray %% in format '%s'" % format)
|
||||||
|
|
|
@ -218,6 +218,12 @@ class StrptimeTests(unittest.TestCase):
|
||||||
else:
|
else:
|
||||||
self.fail("'%s' did not raise ValueError" % bad_format)
|
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):
|
def test_unconverteddata(self):
|
||||||
# Check ValueError is raised when there is unconverted data
|
# Check ValueError is raised when there is unconverted data
|
||||||
self.assertRaises(ValueError, _strptime._strptime_time, "10 12", "%m")
|
self.assertRaises(ValueError, _strptime._strptime_time, "10 12", "%m")
|
||||||
|
|
|
@ -193,6 +193,12 @@ class TimeTestCase(unittest.TestCase):
|
||||||
self.assertRaises(TypeError, time.strptime, b'2009', "%Y")
|
self.assertRaises(TypeError, time.strptime, b'2009', "%Y")
|
||||||
self.assertRaises(TypeError, time.strptime, '2009', b'%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):
|
def test_asctime(self):
|
||||||
time.asctime(time.gmtime(self.t))
|
time.asctime(time.gmtime(self.t))
|
||||||
|
|
||||||
|
|
|
@ -304,6 +304,9 @@ Core and Builtins
|
||||||
Library
|
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 #14254: IDLE now handles readline correctly across shell restarts.
|
||||||
|
|
||||||
- Issue #17614: IDLE no longer raises exception when quickly closing a file.
|
- Issue #17614: IDLE no longer raises exception when quickly closing a file.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue