This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: re module needs to support bytes / memoryview well
Type: behavior Stage:
Components: Versions: Python 3.0
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: benjamin.peterson, gvanrossum, serhiy.storchaka, timehorse
Priority: normal Keywords:

Created on 2007-10-15 23:26 by gvanrossum, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (5)
msg56472 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2007-10-15 23:26
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.
msg82582 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2009-02-21 21:05
re has supported bytes for a while now.
msg230855 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-11-08 13:16
Actually non-hashable patterns are not supported.

>>> 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'

Should it be considered as a bug?
msg230872 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2014-11-08 18:04
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. :-)
msg230874 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-11-08 20:27
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.
History
Date User Action Args
2022-04-11 14:56:27adminsetgithub: 45623
2014-11-08 20:27:32serhiy.storchakasetmessages: + msg230874
2014-11-08 18:04:49gvanrossumsetmessages: + msg230872
2014-11-08 13:16:22serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg230855
2009-02-21 21:05:47benjamin.petersonsetstatus: open -> closed
nosy: + benjamin.peterson
resolution: accepted -> out of date
messages: + msg82582
2008-09-28 19:26:58timehorsesetnosy: + timehorse
2008-01-06 22:29:45adminsetkeywords: - py3k
versions: Python 3.0
2007-11-24 14:17:23georg.brandlsettype: enhancement -> behavior
2007-11-08 14:52:51christian.heimessetpriority: normal
type: enhancement
resolution: accepted
keywords: + py3k
2007-10-15 23:26:51gvanrossumcreate