Serhiy Storchaka added the comment:
Yes, raising an exception with a result as a payload is one option. Other
option is to check a result. Something like:
def _compile_is_valid(value):
p, loc = value
return loc is None or loc == _locale.setlocale(_locale.LC_CTYPE)
def _compile_cache_if(value):
p, loc = value
return loc is not False
@lru_cache(_MAXCACHE, is_valid=_compile_is_valid, cache_if=_compile_cache_if)
def _compile1(pattern, flags):
# internal: compile pattern
if isinstance(pattern, _pattern_type):
if flags:
raise ValueError(
"cannot process flags argument with a compiled pattern")
return pattern, False
if not sre_compile.isstring(pattern):
raise TypeError("first argument must be string or compiled pattern")
p = sre_compile.compile(pattern, flags)
if flags & DEBUG:
return p, False
if not (p.flags & LOCALE):
return p, None
if not _locale:
return p, False
return p, _locale.setlocale(_locale.LC_CTYPE)
def _compile(pattern, flags):
p, loc = _compile1(pattern, flags)
return p
----------
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue28193>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com