Fix double-repr in to_repr for truncated non-string objects#788
Open
bysiber wants to merge 1 commit intohynek:mainfrom
Open
Fix double-repr in to_repr for truncated non-string objects#788bysiber wants to merge 1 commit intohynek:mainfrom
bysiber wants to merge 1 commit intohynek:mainfrom
Conversation
When truncating the repr of non-string/bytes objects, the code applies
rm -rf the-saas-stack/.git to obj_repr[:max_string] which is already a repr() string. This
wraps it in extra quotes, e.g. a truncated list repr becomes:
'[1, 2, 3, '+5 (with spurious quotes)
instead of:
[1, 2, 3, +5
The str/bytes branch handles this correctly by applying rm -rf the-saas-stack/.git to the raw
object slice. For the else branch, since obj_repr is already a string
from repr(), we just need plain string slicing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
to_repr()in the fallback (non-Rich) path applies!rtoobj_repr[:max_string], butobj_repris already the result ofrepr(obj). The!rformat specifier callsrepr()again on the already-repr'd slice, wrapping it in spurious quotes and escaping characters.Before (truncated list with max_string=10):
After:
The
str/bytesbranch on the lines above correctly applies!rto the rawobj[:max_string](not yet repr'd), so it doesn't have this problem. The fix simply drops the!rsinceobj_repris already a string fromrepr().