Skip to content

Buggy or strange behaviour matching mutable data with re #143516

@petersuttondev

Description

@petersuttondev

Bug report

Bug description:

import re
data = bytearray(b'1')
match = re.match(b'1', data)
print(match[0])  # b'1'
data[:] = b'2'
print(match[0])  # b'2'

If you match against mutable data (e.g., a bytearray) and change that data after matching, the matched values reported by the match change.

Is this a) a bug or b) strange behavior that should be pointed out in the docs (or c) none of the above)?

CPython versions tested on:

3.13

Operating systems tested on:

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions