Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Conflict between rich progress and click.echo() #828

Closed
serhiy-storchaka opened this issue Dec 17, 2020 · 1 comment
Closed

[BUG] Conflict between rich progress and click.echo() #828

serhiy-storchaka opened this issue Dec 17, 2020 · 1 comment
Labels
accepted Task was accepted

Comments

@serhiy-storchaka
Copy link

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

@willmcgugan willmcgugan added accepted Task was accepted and removed Needs triage labels Dec 17, 2020
@willmcgugan
Copy link
Collaborator

Fixed in 9.5.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted Task was accepted
Projects
None yet
Development

No branches or pull requests

2 participants