Skip to content

re module needs to support bytes / memoryview well #45623

Closed

Description

@gvanrossum
BPO 1282
Nosy @gvanrossum, @benjaminp, @serhiy-storchaka

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2009-02-21.21:05:47.025>
created_at = <Date 2007-10-15.23:26:51.611>
labels = ['type-bug']
title = 're module needs to support bytes / memoryview well'
updated_at = <Date 2014-11-08.20:27:32.486>
user = 'https://github.com/gvanrossum'

bugs.python.org fields:

activity = <Date 2014-11-08.20:27:32.486>
actor = 'serhiy.storchaka'
assignee = 'none'
closed = True
closed_date = <Date 2009-02-21.21:05:47.025>
closer = 'benjamin.peterson'
components = []
creation = <Date 2007-10-15.23:26:51.611>
creator = 'gvanrossum'
dependencies = []
files = []
hgrepos = []
issue_num = 1282
keywords = []
message_count = 5.0
messages = ['56472', '82582', '230855', '230872', '230874']
nosy_count = 4.0
nosy_names = ['gvanrossum', 'timehorse', 'benjamin.peterson', 'serhiy.storchaka']
pr_nums = []
priority = 'normal'
resolution = 'out of date'
stage = None
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue1282'
versions = ['Python 3.0']

Activity

  1. gvanrossum commented on Oct 15, 2007

    @gvanrossum
    MemberAuthor

    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.

  2. added
    type-bugAn unexpected behavior, bug, or error
    and removed
    type-featureA feature request or enhancement
    on Nov 24, 2007
  3. benjaminp commented on Feb 21, 2009

    @benjaminp
    Contributor

    re has supported bytes for a while now.

  4. serhiy-storchaka commented on Nov 8, 2014

    @serhiy-storchaka
    Member

    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?

  5. gvanrossum commented on Nov 8, 2014

    @gvanrossum
    MemberAuthor

    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. :-)

  6. serhiy-storchaka commented on Nov 8, 2014

    @serhiy-storchaka
    Member

    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.

  7. transferred this issue fromon Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions