Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: hhatto/autopep8
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.0.0
Choose a base ref
...
head repository: hhatto/autopep8
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.0.1
Choose a head ref
  • 19 commits
  • 7 files changed
  • 3 contributors

Commits on Oct 28, 2022

  1. Copy the full SHA
    a941cf6 View commit details
  2. Add 'python_requires=">=3.6"' to match tomli package

    By adding a dependency on the `tomli` packages, which only has versions
    available for python >=3.6 (>=3.7 for the lastest version at the
    moment), `autopep8` effectively became compatible with python >=3.6
    also.
    This changes reflects that by properly providing the `Requires-Python` package
    metadata
    (https://packaging.python.org/en/latest/guides/dropping-older-python-versions/#specify-the-version-ranges-for-supported-python-distributions).
    vphilippon committed Oct 28, 2022
    Copy the full SHA
    25a95c1 View commit details
  3. Merge pull request #656 from vphilippon/add-python-requires

    Add 'python_requires=">=3.6"' to match tomli package
    hhatto authored Oct 28, 2022
    Copy the full SHA
    d529105 View commit details

Commits on Nov 5, 2022

  1. Copy the full SHA
    dbe5e5c View commit details

Commits on Nov 28, 2022

  1. update actions

    hhatto committed Nov 28, 2022
    Copy the full SHA
    2755d5b View commit details

Commits on Nov 29, 2022

  1. Copy the full SHA
    f9149e1 View commit details
  2. remove: w602 fixed method

    hhatto committed Nov 29, 2022
    Copy the full SHA
    25eda3f View commit details
  3. remove global fixes

    hhatto committed Nov 29, 2022
    Copy the full SHA
    a7e7c9a View commit details
  4. strict flake8

    hhatto committed Nov 29, 2022
    Copy the full SHA
    bc6ceab View commit details
  5. update readme

    hhatto committed Nov 29, 2022
    Copy the full SHA
    2b1ead2 View commit details

Commits on Dec 3, 2022

  1. remove: w601-4's tests

    hhatto committed Dec 3, 2022
    Copy the full SHA
    cd745b9 View commit details
  2. Merge pull request #659 from hhatto/pycodestyle2100

    require pycodestyle 2.10.0 and higher version
    hhatto authored Dec 3, 2022
    Copy the full SHA
    8e1e764 View commit details
  3. Copy the full SHA
    b634d6b View commit details
  4. Merge pull request #658 from hhatto/update-actions

    update actions
    hhatto authored Dec 3, 2022
    Copy the full SHA
    74fd023 View commit details
  5. Copy the full SHA
    1f74c0b View commit details
  6. Merge pull request #654 from mgorny/tomllib

    Support using built-in tomllib in Python 3.11
    hhatto authored Dec 3, 2022
    Copy the full SHA
    d0289ea View commit details

Commits on Dec 15, 2022

  1. Copy the full SHA
    b7154f4 View commit details
  2. Merge pull request #663 from hhatto/fix-issue662

    fix: e265, e266
    hhatto authored Dec 15, 2022
    Copy the full SHA
    f75e8f6 View commit details
  3. version 2.0.1

    hhatto committed Dec 15, 2022
    Copy the full SHA
    3555a19 View commit details
Showing with 38 additions and 374 deletions.
  1. +2 −2 .github/workflows/codeql-analysis.yml
  2. +1 −15 README.rst
  3. +9 −34 autopep8.py
  4. +2 −1 setup.py
  5. +0 −12 test/suite/W60.py
  6. +0 −12 test/suite/out/W60.py
  7. +24 −298 test/test_autopep8.py
4 changes: 2 additions & 2 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -47,7 +47,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1
uses: github/codeql-action/autobuild@v2

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
uses: github/codeql-action/analyze@v2
16 changes: 1 addition & 15 deletions README.rst
Original file line number Diff line number Diff line change
@@ -245,10 +245,6 @@ autopep8 fixes the following issues_ reported by pycodestyle_::
W391 - Remove trailing blank lines.
W503 - Fix line break before binary operator.
W504 - Fix line break after binary operator.
W601 - Use "in" rather than "has_key()".
W602 - Fix deprecated form of raising exception.
W603 - Use "!=" instead of "<>"
W604 - Use "repr()" instead of backticks.
W605 - Fix invalid escape sequence 'x'.
W690 - Fix various deprecated code (via lib2to3).

@@ -303,13 +299,6 @@ to fix various types of indentation issues::

$ autopep8 --select=E1,W1 <filename>

Similarly, to just fix deprecated code::

$ autopep8 --aggressive --select=W6 <filename>

The above is useful when trying to port a single code base to work with both
Python 2 and Python 3 at the same time.

If the file being fixed is large, you may want to enable verbose progress
messages::

@@ -354,9 +343,6 @@ function:
Or with options:

>>> import autopep8
>>> autopep8.fix_code('x.has_key(y)\n',
... options={'aggressive': 1})
'y in x\n'
>>> autopep8.fix_code('print( 123 )\n',
... options={'ignore': ['E']})
'print( 123 )\n'
@@ -405,7 +391,7 @@ Testing
Test cases are in ``test/test_autopep8.py``. They can be run directly via
``python test/test_autopep8.py`` or via tox_. The latter is useful for
testing against multiple Python interpreters. (We currently test against
CPython versions 2.7, 3.6 3.7 and 3.8. We also test against PyPy.)
CPython versions 3.7, 3.8, 3.9 and 3.10. We also test against PyPy.)

.. _`tox`: https://pypi.org/project/tox/

43 changes: 9 additions & 34 deletions autopep8.py
Original file line number Diff line number Diff line change
@@ -89,7 +89,7 @@ class documentation for more information.
from pycodestyle import STARTSWITH_INDENT_STATEMENT_REGEX


__version__ = '2.0.0'
__version__ = '2.0.1'


CR = '\r'
@@ -129,15 +129,10 @@ class documentation for more information.
# to be enabled, disable both of them
CONFLICTING_CODES = ('W503', 'W504')

SELECTED_GLOBAL_FIXED_METHOD_CODES = ['W602', ]

# W602 is handled separately due to the need to avoid "with_traceback".
CODE_TO_2TO3 = {
'E231': ['ws_comma'],
'E721': ['idioms'],
'W601': ['has_key'],
'W603': ['ne'],
'W604': ['repr'],
'W690': ['apply',
'except',
'exitfunc',
@@ -1779,14 +1774,6 @@ def fix_2to3(source,
filename=filename)


def fix_w602(source, aggressive=True):
"""Fix deprecated form of raising exception."""
if not aggressive:
return source

return refactor(source, ['raise'], ignore='with_traceback')


def find_newline(source):
"""Return type of newline used in source.
@@ -3343,7 +3330,7 @@ def filter_results(source, results, aggressive):
continue

if r['line'] in commented_out_code_line_numbers:
if issue_id.startswith(('e26', 'e501')):
if issue_id.startswith(('e261', 'e262', 'e501')):
continue

# Do not touch indentation if there is a token error caused by
@@ -3547,22 +3534,10 @@ def fix_lines(source_lines, options, filename=''):
# Disable "apply_local_fixes()" for now due to issue #175.
fixed_source = tmp_source
else:
pep8_options = {
'ignore': options.ignore,
'select': options.select,
'max_line_length': options.max_line_length,
'hang_closing': options.hang_closing,
}
sio = io.StringIO(tmp_source)
contents = sio.readlines()
results = _execute_pep8(pep8_options, contents)
codes = {result['id'] for result in results
if result['id'] in SELECTED_GLOBAL_FIXED_METHOD_CODES}
# Apply global fixes only once (for efficiency).
fixed_source = apply_global_fixes(tmp_source,
options,
filename=filename,
codes=codes)
filename=filename)

passes = 0
long_line_ignore_cache = set()
@@ -3684,9 +3659,6 @@ def apply_global_fixes(source, options, where='global', filename='',
)

for (code, function) in global_fixes():
if code.upper() in SELECTED_GLOBAL_FIXED_METHOD_CODES \
and code.upper() not in codes:
continue
if code_match(code, select=options.select, ignore=options.ignore):
if options.verbose:
print('---> Applying {} fix for {}'.format(where,
@@ -4046,13 +4018,16 @@ def read_config(args, parser):

def read_pyproject_toml(args, parser):
"""Read pyproject.toml and load configuration."""
import tomli
if sys.version_info >= (3, 11):
import tomllib
else:
import tomli as tomllib

config = None

if os.path.exists(args.global_config):
with open(args.global_config, "rb") as fp:
config = tomli.load(fp)
config = tomllib.load(fp)

if not args.ignore_local_config:
parent = tail = args.files and os.path.abspath(
@@ -4061,7 +4036,7 @@ def read_pyproject_toml(args, parser):
pyproject_toml = os.path.join(parent, "pyproject.toml")
if os.path.exists(pyproject_toml):
with open(pyproject_toml, "rb") as fp:
config = tomli.load(fp)
config = tomllib.load(fp)
break
(parent, tail) = os.path.split(parent)

3 changes: 2 additions & 1 deletion setup.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@


INSTALL_REQUIRES = (
['pycodestyle >= 2.9.1', 'tomli']
['pycodestyle >= 2.10.0', 'tomli; python_version < "3.11"']
)


@@ -51,6 +51,7 @@ def version():
],
keywords='automation, pep8, format, pycodestyle',
install_requires=INSTALL_REQUIRES,
python_requires=">=3.6",
test_suite='test.test_autopep8',
py_modules=['autopep8'],
zip_safe=False,
12 changes: 0 additions & 12 deletions test/suite/W60.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
#: W601
if a.has_key("b"):
print a
#: W602
raise DummyError, "Message"
#: W602
raise ValueError, "hello %s %s" % (1, 2)
#: Okay
raise type_, val, tb
raise Exception, Exception("f"), t
#: W603
if x <> 0:
x = 0
#: W604
val = `1 + 2`
12 changes: 0 additions & 12 deletions test/suite/out/W60.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
#: W601
if "b" in a:
print a
#: W602
raise DummyError, "Message"
#: W602
raise ValueError, "hello %s %s" % (1, 2)
#: Okay
raise type_, val, tb
raise Exception, Exception("f"), t
#: W603
if x != 0:
x = 0
#: W604
val = repr(1 + 2)
Loading