-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Description
There is a conflict between rich.progress.Progress and click.echo().
The rich.progress.Progress context manager monkey-patches sys.stdout. click.echo() detects whether sys.stdout is a text stream or byte stream (this is questionable, but it is a different issue) by trying to write an empty bytes object. If the test is passed successfully, then it is a bytes stream, and click encodes string before writing it. But the wrapper instantiated by Progress ignores empty input for write(), including empty bytes object, therefore click.echo() concludes that it is a byte stream.
Example:
import click
from rich.progress import Progress
with Progress():
click.echo('test')Traceback:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File ".../site-packages/click/utils.py", line 272, in echo
file.write(message)
File ".../site-packages/rich/progress.py", line 491, in write
line, new_line, text = text.partition("\n")
TypeError: a bytes-like object is required, not 'str'
It is not completely a failure of rich, but it would be better if the wrapper better emulate output text stream. In particularly check that the argument of write() is string.
rich 9.3.0