hhatto / autopep8

A tool that automatically formats Python code to conform to the PEP 8 style guide.
https://pypi.org/project/autopep8/
MIT License
4.54k stars 291 forks source link

module 'pycodestyle' has no attribute 'missing_whitespace_around_operator' #689

Closed adrianwix closed 11 months ago

adrianwix commented 11 months ago

Python Code

image

Command Line and Configuration

.pep8, setup.cfg, ...

Whatever comes as default after installing autopep8 for the first time

Command Line

$ autopep8 -a -a --in-place --recursive --exclude postgres,pgadmin,demo_data . 

Your Environment

adrianwix commented 11 months ago

I can't find a missing_whitespace_around_operator anywhere inside https://github.com/PyCQA/pycodestyle

justindarcy commented 11 months ago

I am seeing this issue as well image

TylerJang27 commented 11 months ago

Running into this as well. I think https://pypi.org/project/pycodestyle/#history released a breaking change in 2.11.0 that is hitting this. As a temporary fix I'm able to pin pycodestyle to 2.10.0, but ideally autopep8 would be able to handle this out of the box now.

MiltiadisKoutsokeras commented 11 months ago

I can confirm that problem in our code checking also. We use autopep8==2.0.2 and the stack trace is the following:

Traceback (most recent call last):
  File "<Project path here>/.venv/bin/autopep8", line 8, in <module>
    sys.exit(main())
  File "<Project path here>/.venv/lib/python3.9/site-packages/autopep8.py", line 4528, in main
    results = fix_multiple_files(args.files, args, sys.stdout)
  File "<Project path here>/.venv/lib/python3.9/site-packages/autopep8.py", line 4423, in fix_multiple_files
    ret = _fix_file((name, options, output))
  File "<Project path here>/.venv/lib/python3.9/site-packages/autopep8.py", line 4393, in _fix_file
    return fix_file(*parameters)
  File "<Project path here>/.venv/lib/python3.9/site-packages/autopep8.py", line 3589, in fix_file
    fixed_source = fix_lines(fixed_source, options, filename=filename)
  File "<Project path here>/.venv/lib/python3.9/site-packages/autopep8.py", line 3569, in fix_lines
    fixed_source = fix.fix()
  File "<Project path here>/.venv/lib/python3.9/site-packages/autopep8.py", line 613, in fix
    self._fix_source(filter_results(source=''.join(self.source),
  File "<Project path here>/.venv/lib/python3.9/site-packages/autopep8.py", line 557, in _fix_source
    modified_lines = fix(result)
  File "<Project path here>/.venv/lib/python3.9/site-packages/autopep8.py", line 761, in fix_e225
    pycodestyle.missing_whitespace_around_operator(fixed, ts))
AttributeError: module 'pycodestyle' has no attribute 'missing_whitespace_around_operator'
shaperilio commented 11 months ago

There are several pull requests for this; #699, #696, #691, #690 are all the same. I suggest someone look into this comment and push their PR forward with a solution.

keriksson-rosenqvist commented 11 months ago

This is a possible solution that allows pycodestyle >= 2.11.0. https://github.com/hhatto/autopep8/pull/696

ststefa commented 9 months ago

For the records, I had the same problem with pycodestyle 2.10.0. Just now, I tried it with 2.11.1 and it seems to be solved.

folkien commented 8 months ago

Is solution to this error avaiable now or we have to wait?

Errors still remains on my setup (python 3.11) : pycodestyle==2.11.1 autopep8==2.0.4

hhatto commented 8 months ago

This problem is solved in https://github.com/hhatto/autopep8/pull/699/files. This change has also been released in autopep8 v2.0.4.

Please add a new issue if you have problems. Please include a code example of when the problem occurs.

juanreyes00 commented 5 months ago

I got this problem with my pre-commit configuration, the solution was update the hook to the last version.

pycodestyle==2.11.1 autopep8==2.0.4 Python 3.11

  - repo: https://github.com/pre-commit/mirrors-autopep8
    rev: v2.0.4
    hooks:
      - id: autopep8
essamgouda97 commented 4 months ago

I got this problem with my pre-commit configuration, the solution was update the hook to the last version.

pycodestyle==2.11.1 autopep8==2.0.4 Python 3.11

  - repo: https://github.com/pre-commit/mirrors-autopep8
    rev: v2.0.4
    hooks:
      - id: autopep8

That worked, thanks !