diff -r 6898e1afc216 Lib/re.py --- a/Lib/re.py Sat Mar 16 23:00:16 2013 +0200 +++ b/Lib/re.py Sat Mar 16 23:27:06 2013 +0200 @@ -211,7 +211,14 @@ def compile(pattern, flags=0): "Compile a regular expression pattern, returning a pattern object." - return _compile(pattern, flags) + if isinstance(pattern, _pattern_type): + if flags: + raise ValueError( + "Cannot process flags argument with a compiled pattern") + return pattern + if not sre_compile.isstring(pattern): + raise TypeError("first argument must be string or compiled pattern") + return sre_compile.compile(pattern, flags) def purge(): "Clear the regular expression caches" @@ -271,14 +278,7 @@ return _cache[type(pattern), pattern, flags] except KeyError: pass - if isinstance(pattern, _pattern_type): - if flags: - raise ValueError( - "Cannot process flags argument with a compiled pattern") - return pattern - if not sre_compile.isstring(pattern): - raise TypeError("first argument must be string or compiled pattern") - p = sre_compile.compile(pattern, flags) + p = compile(pattern, flags) if len(_cache) >= _MAXCACHE: _cache.clear() _cache[type(pattern), pattern, flags] = p diff -r 6898e1afc216 Misc/NEWS --- a/Misc/NEWS Sat Mar 16 23:00:16 2013 +0200 +++ b/Misc/NEWS Sat Mar 16 23:27:06 2013 +0200 @@ -283,6 +283,8 @@ Library ------- +- Issue #17441: re.compile() no more cached. + - Issue #16389: Fixed a performance regression relative to Python 3.1 in the caching of compiled regular expressions.