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

write directly to sys.stdout.buffer to avoid windows io encoding #1382

Merged
merged 1 commit into from
Sep 8, 2021

Conversation

asottile
Copy link
Member

@asottile asottile commented Sep 8, 2021

resolves #1381

@asottile asottile added this to the 4.0.0 milestone Sep 8, 2021
@asottile asottile merged commit eea1066 into master Sep 8, 2021
@asottile asottile deleted the stdio-encoding-sadness branch September 8, 2021 21:20
@@ -130,21 +125,15 @@ def test_write_uses_an_output_file(tee):
]


@mock.patch("flake8.formatting.base.print")
def test_write_uses_print(print_function):
def test_write_uses_print(capsys):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should rename this too

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh yeah good point!

@HebaruSan
Copy link

Flake8 throws AttributeError on this line now. Any suggestions?

https://github.com/KSP-CKAN/NetKAN-Infra/pull/228/checks?check_run_id=3886107937

=================================== FAILURES ===================================
_________________________________ FLAKE8-check _________________________________
/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/pluggy/_hooks.py:265: in __call__
    return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/pluggy/_manager.py:80: in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/_pytest/runner.py:170: in pytest_runtest_call
    raise e
/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/_pytest/runner.py:162: in pytest_runtest_call
    item.runtest()
/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/pytest_flake8.py:127: in runtest
    self.statistics)
/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/py/_io/capture.py:150: in call
    res = func(*args, **kwargs)
/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/pytest_flake8.py:222: in check_file
    app.report_errors()
/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/flake8/main/application.py:309: in report_errors
    results = self.file_checker_manager.report()
/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/flake8/checker.py:249: in report
    results_reported += self._handle_results(filename, results)
/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/flake8/checker.py:161: in _handle_results
    physical_line=physical_line,
/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/flake8/style_guide.py:430: in handle_error
    code, filename, line_number, column_number, text, physical_line
/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/flake8/style_guide.py:581: in handle_error
    self.formatter.handle(error)
/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/flake8/formatting/base.py:100: in handle
    self.write(line, source)
/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/flake8/formatting/base.py:203: in write
    self._write(line)
/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/flake8/formatting/base.py:187: in _write
    sys.stdout.buffer.write(output.encode() + self.newline.encode())
E   AttributeError: '_io.StringIO' object has no attribute 'buffer'

@HebaruSan
Copy link

Why the downthumbs on my previous comment, @asottile and @sigmavirus24? Line 187 of base.py is throwing an AttributeError when trying to access sys.stdout.buffer, and this pull request added that. If you already know why that is, would you mind sharing?

@asottile
Copy link
Member Author

because you failed to look at pinned issues or do any due diligence and you're using an unsupported private api

@HebaruSan
Copy link

I'm not using any API, I'm just running pytest with this in pytest.ini, to consolidate all of our Python tooling into a single output format:

[pytest]
addopts = -p no:cacheprovider --mypy --pylint --flake8

I've looked at the pinned issue. It says something about monkeypatching sys.stdout, and something else about io.TextIOWrapper, and then it was closed. I'm not monkeypatching anything, so that's not much help.

I guess the key takeaway here is that people are having flake8 break on them without themselves commiting whatever heinous technical sin so offends you here, because apparently pytest did it. I would suggest reconsidering how you are approaching that segment of your user base.

@asottile
Copy link
Member Author

it's not pytest either, place your blame on pytest-flake8

also please adjust your attitude

@PyCQA PyCQA locked as resolved and limited conversation to collaborators Nov 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

flake8 crash on windows-latest with UnicodeEncodeError
3 participants