Great spot. .groups (and .groupdict with named capturing groups) behave similarly - they must also work on an underlying index. This isn’t surprising - re.Match provides methods returning indices: .start, .end, .span.
I’m thinking it’s more that the various regular expression modules in Python over the years were written when all their candidate inputs were immutable. I don’t know when the mutable bytearray object was added, but I’m pretty sure it was well after regular expressions.
So yes, an optimization, but maybe made when all searchable types were immutable.
Assuming this is intended behaviour, it’s worth adding to the re docs. Just so people are aware of the potential footgun, and those that bother to read them or do a search have something definitive to refer to. They’re far from concise currently, a little foot note won’t hurt.