You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Flake 8 - StringIO wrapper error with [FLAKE8 - AttributeError: '_io.StringIO' object has no attribute 'buffer'] #81
Please describe the problem or feature
I have a project where flake aparently works as intended, and when I use the commandline flake it still works to some extent without all the pytest.ini setup, but within the Pipenv project it fails through pytest when it finds an error.
I run flake8:
$ python -m pytest --flake8
In all other projects we have it works flawlessly, and I really like the tool :D
In general the error comes when the file contains an error and flake8 tries to write to stdout.
This is my pipfile (removed the internal libs, but they dont wrap output in any way:
checked the locks, and same lib versions as bug-report and:
pytest 6.2.5
pytest-flake8 1.0.7
We have the same setup in other projects without the same issue so I'm a bit confused.
I however suspect something wrap the stdout StringIO so the expected attributes are not accessible by flake when it needs to report its findings.
Reacted by Mike Fiedler, Maciej Olko and harmbuisman
That has been the flake8 maintenance team's attitude since flake8 2.x. 3.0 reinforced that. This isn't new and contrary to your implications isn't arbitrary
Just described my findings on the subject to help the libraries maintainer. I have no desire running circles around three product teams trying to convenience someone to do something.
I'm not associated with any of the projects so I don't have any intrinsic stakes in any of them succeeding.
I did choose to raise PR against flake8 just because I thought that that change contributed to the Python community the most. Rather than py.io that seems mostly dead or pytest-flake8 integration that isn't doing anything that usual or bad.
Reacted by Thijs Kramer, Joël Bourgault and StassDavid
――――――――――――――――――――――――――――――――――― FLAKE8-check ―――――――――――――――――――――――――――――――――――
.venv/lib/python3.9/site-packages/pluggy/_hooks.py:265: in __call__
return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
.venv/lib/python3.9/site-packages/pluggy/_manager.py:80: in _hookexec
return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
.venv/lib/python3.9/site-packages/_pytest/runner.py:170: in pytest_runtest_call
raise e
.venv/lib/python3.9/site-packages/_pytest/runner.py:162: in pytest_runtest_call
item.runtest()
.venv/lib/python3.9/site-packages/pytest_flake8.py:120: in runtest
found_errors, out, err = call(
.venv/lib/python3.9/site-packages/py/_io/capture.py:150: in call
res = func(*args, **kwargs)
.venv/lib/python3.9/site-packages/pytest_flake8.py:222: in check_file
app.report_errors()
.venv/lib/python3.9/site-packages/flake8/main/application.py:309: in report_errors
results = self.file_checker_manager.report()
.venv/lib/python3.9/site-packages/flake8/checker.py:247: in report
results_reported += self._handle_results(filename, results)
.venv/lib/python3.9/site-packages/flake8/checker.py:153: in _handle_results
reported_results_count += style_guide.handle_error(
.venv/lib/python3.9/site-packages/flake8/style_guide.py:429: in handle_error
return guide.handle_error(
.venv/lib/python3.9/site-packages/flake8/style_guide.py:581: in handle_error
self.formatter.handle(error)
.venv/lib/python3.9/site-packages/flake8/formatting/base.py:100: in handle
self.write(line, source)
.venv/lib/python3.9/site-packages/flake8/formatting/base.py:203: in write
self._write(line)
.venv/lib/python3.9/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'
Problem only occured with 4.0.0 and 4.0.1. Downgrading to 3.9.2 fixed the problem!
Activity
klausmyrseth commentedon Oct 13, 2021
I forceably downgraded flake 4.0.1 to 3.9.2 in my Pipfile so the updated version looks like:
and it started working again, so there is something going on with the new flake 4.0.1
IljaOrlovs commentedon Oct 13, 2021
My PR to fix this on the flake8 side had been rejected. :-(
PyCQA/flake8#1422
IljaOrlovs commentedon Oct 13, 2021
This is more an integration issue between flake9 and pytests's "py.io.StdCapture" class. Sadly, flake8 developer seems to be quite adamant that he is developing an CLI tool rather than a library ( https://flake8.pycqa.org/en/latest/user/python-api.html ), so he can claim that the issue should be fixed elsewhere
sigmavirus24 commentedon Oct 13, 2021
That has been the flake8 maintenance team's attitude since flake8 2.x. 3.0 reinforced that. This isn't new and contrary to your implications isn't arbitrary
IljaOrlovs commentedon Oct 13, 2021
I did not try to imply anything, sir.
Just described my findings on the subject to help the libraries maintainer. I have no desire running circles around three product teams trying to convenience someone to do something.
I'm not associated with any of the projects so I don't have any intrinsic stakes in any of them succeeding.
IljaOrlovs commentedon Oct 13, 2021
I did choose to raise PR against flake8 just because I thought that that change contributed to the Python community the most. Rather than py.io that seems mostly dead or pytest-flake8 integration that isn't doing anything that usual or bad.
BracketJohn commentedon Oct 14, 2021
I've encountered the same exception:
Problem only occured with
4.0.0and4.0.1. Downgrading to3.9.2fixed the problem!Remove Python 2 support and dependency on py, fixes tholo#81
erikkemperman commentedon Oct 16, 2021
If you can live with dropping support for Python 2, #82 might fix this.
Remove Python 2 support and dependency on py, fixes tholo#81
Pin flake8 to version 3 to prevent StringIO error see tholo/pytest-fl…
Pin flake8 to version 3 to prevent StringIO error see tholo/pytest-fl…
Pin flake8 to version 3 to prevent StringIO error see tholo/pytest-fl…
Pin flake8 to version 3 to prevent StringIO error see tholo/pytest-fl…
Pin flake8 to version 3 to prevent StringIO error see tholo/pytest-fl…
35 remaining items
Run flake8 only via pre-commit
Merge fixes from erikkemberman@
Remove Python 2 support and dependency on py, fixes #81
Merge fixes from erikkemberman@
jaraco commentedon Mar 5, 2022
Thanks for the fix and release in 1.1.0!
Drop flake8 pinning: tholo/pytest-flake8#81 fixed
Pin flake8 to version 3 to prevent StringIO error see tholo/pytest-fl…
Pin flake8 to version 3 to prevent StringIO error see tholo/pytest-fl…
Pin flake8 to version 3 to prevent StringIO error see tholo/pytest-fl…
Downgrade flake8 to 3.9.2 to avoid tholo/pytest-flake8#81
Downgrade flake8 to 3.9.2 to avoid tholo/pytest-flake8#81
Downgrade flake8 to 3.9.2 to avoid tholo/pytest-flake8#81
Run flake8 and isort separately
Downgrade and pin flake8 to fix CI