You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
reprlib.Repr truncation ignores the length of a custom fillvalue #161289
Since Python 3.11, reprlib.Repr.fillvalue can be set to any string, but Repr.repr_str(), Repr.repr_int() and Repr.repr_instance() still compute how many characters to keep around it as if it were always three characters long (the length of the default '...'):
As a result, when the fill value has a different length, a truncated representation no longer fits maxstring, maxlong or maxother:
>>>importreprlib>>>r=reprlib.Repr(maxstring=10, maxlong=10, maxother=10, fillvalue='<snip>')
>>>r.repr(12345678901234567890) # 13 characters, maxlong is 10'123<snip>7890'>>>r.repr('abcdefghijklmnopqrstuvwxyz') # 13 characters, maxstring is 10"'ab<snip>xyz'">>>r=reprlib.Repr(maxstring=10, fillvalue='…')
>>>r.repr('abcdefghijklmnopqrstuvwxyz') # 8 characters, 2 left unused"'ab…xyz'"
The documentation describes maxlong as the "Maximum number of characters in the representation for an integer". Using len(self.fillvalue) instead of 3 makes the result fit the limit, and leaves the output with the default '...' unchanged.
Activity