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

Errors with new colorama #770

Closed
ericfrederich opened this issue Apr 26, 2017 · 4 comments
Closed

Errors with new colorama #770

ericfrederich opened this issue Apr 26, 2017 · 4 comments
Labels
Milestone

Comments

@ericfrederich
Copy link
Contributor

Colorama fixed an issue (here) by copying some CPython bug fix (here)

Now this code fails with colorama==0.3.8:

python -c "import colorama; import click; colorama.init(); click.echo('hi')"

To me it is unclear who is at fault here (click, colorama, the def fileno() which always raises an error?) ... but I thought bugs should be created in both projects. If it turns out that Python "fix" was the problem, one should be opened there as well.

@untitaker
Copy link
Contributor

I can reproduce this on Windows 7:

[Anaconda2] C:\Users\untitaker>python -c "import colorama; import click; colorama.init(); click.echo(42);"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Users\untitaker\AppData\Roaming\Python\Python27\site-packages\click\utils.py", line 217, in echo
    file = _default_text_stdout()
  File "C:\Users\untitaker\AppData\Roaming\Python\Python27\site-packages\click\_compat.py", line 621, in func
    rv = wrapper_func()
  File "C:\Users\untitaker\AppData\Roaming\Python\Python27\site-packages\click\_compat.py", line 201, in get_text_stdout
    rv = _get_windows_console_stream(sys.stdout, encoding, errors)
  File "C:\Users\untitaker\AppData\Roaming\Python\Python27\site-packages\click\_winconsole.py", line 261, in _get_windows_console_stream
    func = _stream_factories.get(f.fileno())
TypeError: fileno() takes no arguments (1 given)

@untitaker untitaker added the bug label Apr 26, 2017
@ericfrederich
Copy link
Contributor Author

@untitaker, it's worth noting that even is they add the self argument to the method all the body does is raise OSError anyway. This is mentioned in the bug on Colorama

@untitaker
Copy link
Contributor

untitaker commented Apr 26, 2017

I understand. As far as I can tell we can work around f not having a proper fileno by catching the OSError, and attempting to compare f against all values in (sys.stdin, sys.stdout, sys.stderr). This way we would obtain the proper fileno again. Another option would be to attempt accessing f.__wrapped.fileno, as __wrapped appears to be the var used by the colorama wrapper.

However, looking at the chain reaction of bug reports that led to this issue, I'm not sure if we should attempt to do anything but wait until that new Python issue gets fixed. Especially since the reason colorama doesn't have a fileno is a workaround itself.

@davidism
Copy link
Member

Seems to have been fixed at some point, possibly by #1135. 7.1 will be out soon.

@davidism davidism added this to the 7.1 milestone Feb 24, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants