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

Json formatter bypasses redirect_stdout #3227

Closed
Martmists-GH opened this issue Oct 31, 2019 · 0 comments
Closed

Json formatter bypasses redirect_stdout #3227

Martmists-GH opened this issue Oct 31, 2019 · 0 comments

Comments

@Martmists-GH
Copy link

Martmists-GH commented Oct 31, 2019

Steps to reproduce

  1. Install pylint
  2. Run it like this:
from contextlib import redirect_stdout
from io import StringIO
from pylint.lint import Run

file = StringIO()
with redirect_stdout(file):
    Run(["some_file.py"], do_exit=False)  # No output


file_2 = StringIO()
with redirect_stdout(file_2):
    Run(["-f", "json", "some_file.py"], do_exit=False)  # JSON output

Current behavior

There is still being written to stdout (I checked stderr with the same method, but according to the source stdout is being used)

Expected behavior

redirect_stdout catches all content written to stdout and writes it to the StringIO instead

pylint --version output

$ pylint --version
pylint 2.4.3
astroid 2.3.1
Python 3.7.4 (default, Oct  4 2019, 06:57:26) 
[GCC 9.2.0]

Cause

json_reporter.py:25
JSONReporter has sys.stdout as default parameter, which causes it to keep a reference to the original output.
To solve this, simply replace sys.stdout with None as it will fetch sys.stdout if the output parameter is falsy.

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

No branches or pull requests

1 participant