rich
rich copied to clipboard
[BUG] Behavior of console.print() with empty *args is different from regular print()
Describe the bug
Expected that console.print(end="!") will print only ! as regular python print(), but it print line break without ending symbol.
from rich.console import Console
console = Console()
for f in (
lambda: print("A", end="!"),
lambda: print(end="!"),
lambda: console.print("A", end="!"),
lambda: console.print(end="!"),
):
print("=>", end="")
f()
print("<=")
Output:
❯ python3 test.py
=>A!<=
=>!<=
=>A!<=
=>
<=
rich == 14.0.0
We found the following entry in the FAQ which you may find helpful:
Feel free to close this issue if you found an answer in the FAQ. Otherwise, please give us a little time to review.
This is an automated reply, generated by FAQtory
I tried reproducing it with your test code, and i can say it does output a line break instead of '!'.
im thinking the issue might be to do with how 'console.print' handles empty content, and could be ignoring the custom 'end' parm
im gonna take a look at the class and write some tests and just try help
I’ve looked at the Console.print method in console.py, which accepts *objects, sep, and end parameters
The issue is likely happening when 'objects' is empty, causing 'print' to default to a new line
The issue happens when *objects is empty, causing print to default to a newline (possibly via self.file.write
Are these lines necessary: https://github.com/Textualize/rich/blob/master/rich/console.py#L1680
if not objects:
objects = (NewLine(),)
?