Fix and test for bug #764548:

Use isinstance() instead of comparing types directly, to enable
subclasses of str and unicode to be used as patterns.
Blessed by /F.
This commit is contained in:
Just van Rossum 2003-07-02 20:03:04 +00:00
parent 5e4e39f12a
commit 12723bacea
3 changed files with 17 additions and 7 deletions

View file

@ -219,9 +219,9 @@ def _compile(*key):
if p is not None:
return p
pattern, flags = key
if type(pattern) is _pattern_type:
if isinstance(pattern, _pattern_type):
return pattern
if type(pattern) not in sre_compile.STRING_TYPES:
if not isinstance(pattern, sre_compile.STRING_TYPES):
raise TypeError, "first argument must be string or compiled pattern"
try:
p = sre_compile.compile(pattern, flags)