mirror of
https://github.com/python/cpython.git
synced 2025-11-26 21:33:10 +00:00
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:
parent
5e4e39f12a
commit
12723bacea
3 changed files with 17 additions and 7 deletions
|
|
@ -428,12 +428,12 @@ def _compile_info(code, pattern, flags):
|
|||
_compile_charset(charset, flags, code)
|
||||
code[skip] = len(code) - skip
|
||||
|
||||
STRING_TYPES = [type("")]
|
||||
|
||||
try:
|
||||
STRING_TYPES.append(type(unicode("")))
|
||||
unicode
|
||||
except NameError:
|
||||
pass
|
||||
STRING_TYPES = type("")
|
||||
else:
|
||||
STRING_TYPES = (type(""), type(unicode("")))
|
||||
|
||||
def _code(p, flags):
|
||||
|
||||
|
|
@ -453,7 +453,7 @@ def _code(p, flags):
|
|||
def compile(p, flags=0):
|
||||
# internal: convert pattern list to internal format
|
||||
|
||||
if type(p) in STRING_TYPES:
|
||||
if isinstance(p, STRING_TYPES):
|
||||
import sre_parse
|
||||
pattern = p
|
||||
p = sre_parse.parse(p, flags)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue