Index: Lib/_strptime.py =================================================================== --- Lib/_strptime.py (revision 70336) +++ Lib/_strptime.py (working copy) @@ -294,8 +294,13 @@ def _strptime(data_string, format="%a %b %d %H:%M:%S %Y"): """Return a time struct based on the input string and the format string.""" + + if isinstance(data_string, bytes): + raise TypeError("strptime() argument 1 must be str, not bytes") + global _TimeRE_cache, _regex_cache - with _cache_lock: + with _cache_lock: + if _getlang() != _TimeRE_cache.locale_time.lang: _TimeRE_cache = TimeRE() _regex_cache.clear() Index: Lib/test/test_time.py =================================================================== --- Lib/test/test_time.py (revision 70336) +++ Lib/test/test_time.py (working copy) @@ -115,6 +115,10 @@ except ValueError: self.fail("conversion specifier %r failed with '%s' input." % (format, strf_output)) + + def test_srptime_bytesarg(self): + self.assertRaises(TypeError, time.strptime, b'2009', "%Y") + def test_asctime(self): time.asctime(time.gmtime(self.t))