Handling of \n
When a string contains '\n' icecream interprets it as a new line, even if the string actually contains '\\n' or equivalent. I would expect the same behavior print shows.
Expected behavior:
ic(r'C:\Users\new test')
ic| r'C:\Users\new test': 'C:\Users\new test'
ic('C:\\Users\\new test')
ic| 'C:\Users\new test': 'C:\Users\new test'
Actual behavior:
ic(r'C:\Users\new test')
ic| r'C:\Users\new test': 'C:\Users
ew test'
ic('C:\\Users\\new test')
ic| 'C:\Users\new test': 'C:\Users
ew test'
Possible Quick Fix (creates new problem)
Changing
@singledispatch
def argumentToString(obj):
s = DEFAULT_ARG_TO_STRING_FUNCTION(obj)
s = s.replace('\\n', '\n') # Preserve string newlines in output.
return s
to
@singledispatch
def argumentToString(obj):
if type(obj) == str:
return obj
else:
s = DEFAULT_ARG_TO_STRING_FUNCTION(obj)
s = s.replace('\\n', '\n') # Preserve string newlines in output.
return s
in icecream.py line 181 onwards will get rid of this speciific problem, but there will be no coloring.
The chosen example of a path shows the problem of this behavior. Especially when paths are entered, the usability suffers. A possible solution would be the introduction of a new parameter that allows the choice of behavior. Of course, this would only circumvent the problem.
The issue has the same roots as the attached one.
There are some updates due this issue: https://github.com/gruns/icecream/releases/tag/untagged-19e3d02255ee5494672f
@ICreedenI
The update solves that: https://github.com/gruns/icecream/releases/tag/v2.1.5