You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
re module needs to support bytes / memoryview well #45623
Once PEP-3137 is fully implemented, the re module needs to be fixed so
that the regex argument, the substitution argument, and the argument
being searched/replaced are allowed to be arbitrary bytes arrays; where
hashing is needed a copy in an immutable bytes object can be made.
>>> re.match(bytearray(b'.'), b'x')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/serhiy/py/cpython/Lib/re.py", line 163, in match
return _compile(pattern, flags).match(string)
File "/home/serhiy/py/cpython/Lib/re.py", line 281, in _compile
p, loc = _cache[type(pattern), pattern, flags]
TypeError: unhashable type: 'bytearray'
Hm, I don't see a reason why the *pattern* should be a bytearray or memoryview, only the string it is searching. But if you fixed it by casting it to bytes I won't stop you. :-)
Activity
gvanrossum commentedon Oct 15, 2007
Once PEP-3137 is fully implemented, the re module needs to be fixed so
that the regex argument, the substitution argument, and the argument
being searched/replaced are allowed to be arbitrary bytes arrays; where
hashing is needed a copy in an immutable bytes object can be made.
benjaminp commentedon Feb 21, 2009
re has supported bytes for a while now.
serhiy-storchaka commentedon Nov 8, 2014
Actually non-hashable patterns are not supported.
Should it be considered as a bug?
gvanrossum commentedon Nov 8, 2014
Hm, I don't see a reason why the *pattern* should be a bytearray or memoryview, only the string it is searching. But if you fixed it by casting it to bytes I won't stop you. :-)
serhiy-storchaka commentedon Nov 8, 2014
It is easy to fix with small (but non zero) cost, but I don't see a reason too.
So I don't reopen this issue.