[issue40984] re.compile's repr truncates patterns at 199 characters

Quentin Wenger report at bugs.python.org
Mon Jun 15 09:29:52 EDT 2020


New submission from Quentin Wenger <wenger.quentin at bluewin.ch>:

This seems somewhat arbitrary and yields unusable results, going against the doc:

> repr(object)
> Return a string containing a printable representation of an object. For many types, this function makes an attempt to return a string that would yield an object with the same value when passed to eval(), otherwise the representation is a string enclosed in angle brackets that contains the name of the type of the object together with additional information often including the name and address of the object. A class can control what this function returns for its instances by defining a __repr__() method.

The truncated representation neither "yields an object with the same value" (it raises a SyntaxError, of course, due to the missing quote and closing parenthesis), nor is "enclosed in angle brackets".


```
>>> import re
>>> re.compile("()"*99)
re.compile('()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()')
>>> re.compile("()"*100)
re.compile('()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()
```

----------
components: Regular Expressions
messages: 371541
nosy: ezio.melotti, matpi, mrabarnett
priority: normal
severity: normal
status: open
title: re.compile's repr truncates patterns at 199 characters
type: behavior
versions: Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue40984>
_______________________________________


More information about the Python-bugs-list mailing list