From 61782ada20c525bf6a036c19a69f44399ce795a4 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 23 Feb 2026 22:30:16 +0000 Subject: [PATCH 1/2] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/asottile/pyupgrade: v2.7.4 → v3.21.2](https://github.com/asottile/pyupgrade/compare/v2.7.4...v3.21.2) - https://github.com/psf/black → https://github.com/psf/black-pre-commit-mirror - [github.com/psf/black-pre-commit-mirror: 20.8b1 → 26.1.0](https://github.com/psf/black-pre-commit-mirror/compare/20.8b1...26.1.0) - https://gitlab.com/pycqa/flake8 → https://github.com/PyCQA/flake8 - [github.com/PyCQA/flake8: 3.8.4 → 7.3.0](https://github.com/PyCQA/flake8/compare/3.8.4...7.3.0) - [github.com/pycqa/isort: 5.7.0 → 8.0.0](https://github.com/pycqa/isort/compare/5.7.0...8.0.0) - [github.com/pre-commit/pygrep-hooks: v1.7.0 → v1.10.0](https://github.com/pre-commit/pygrep-hooks/compare/v1.7.0...v1.10.0) - [github.com/pre-commit/pre-commit-hooks: v3.4.0 → v6.0.0](https://github.com/pre-commit/pre-commit-hooks/compare/v3.4.0...v6.0.0) - [github.com/pre-commit/mirrors-prettier: v2.2.1 → v4.0.0-alpha.8](https://github.com/pre-commit/mirrors-prettier/compare/v2.2.1...v4.0.0-alpha.8) - https://github.com/myint/autoflake → https://github.com/PyCQA/autoflake - [github.com/PyCQA/autoflake: v1.4 → v2.3.3](https://github.com/PyCQA/autoflake/compare/v1.4...v2.3.3) --- .pre-commit-config.yaml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fbf3d37..b42bf8d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,34 +1,34 @@ repos: - repo: https://github.com/asottile/pyupgrade - rev: v2.7.4 + rev: v3.21.2 hooks: - id: pyupgrade args: ["--py36-plus"] - - repo: https://github.com/psf/black - rev: 20.8b1 + - repo: https://github.com/psf/black-pre-commit-mirror + rev: 26.1.0 hooks: - id: black args: ["--target-version", "py36"] - - repo: https://gitlab.com/pycqa/flake8 - rev: 3.8.4 + - repo: https://github.com/PyCQA/flake8 + rev: 7.3.0 hooks: - id: flake8 additional_dependencies: [flake8-2020] - repo: https://github.com/pycqa/isort - rev: 5.7.0 + rev: 8.0.0 hooks: - id: isort - repo: https://github.com/pre-commit/pygrep-hooks - rev: v1.7.0 + rev: v1.10.0 hooks: - id: python-check-blanket-noqa - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v3.4.0 + rev: v6.0.0 hooks: - id: check-merge-conflict - id: check-toml @@ -36,13 +36,13 @@ repos: - id: mixed-line-ending - repo: https://github.com/pre-commit/mirrors-prettier - rev: v2.2.1 + rev: v4.0.0-alpha.8 hooks: - id: prettier args: [--prose-wrap=always, --print-width=88] - - repo: https://github.com/myint/autoflake - rev: v1.4 + - repo: https://github.com/PyCQA/autoflake + rev: v2.3.3 hooks: - id: autoflake args: From 638af943c942b894b5361476e1a781743bf999b6 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 23 Feb 2026 22:30:52 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- modernize/fixes/fix_itertools_imports_six.py | 6 ++---- modernize/fixes/fix_itertools_six.py | 19 +++++++++--------- modernize/fixes/fix_metaclass.py | 21 ++++++++++---------- modernize/fixes/fix_raise.py | 1 + modernize/fixes/fix_raise_six.py | 1 + modernize/fixes/fix_urllib_six.py | 17 ++++++---------- modernize/main.py | 8 ++------ tests/test_fix_imports_six.py | 2 +- tests/test_future_behaviour.py | 4 ++-- tests/utils.py | 2 +- 10 files changed, 36 insertions(+), 45 deletions(-) diff --git a/modernize/fixes/fix_itertools_imports_six.py b/modernize/fixes/fix_itertools_imports_six.py index 8024d71..da2b6ff 100644 --- a/modernize/fixes/fix_itertools_imports_six.py +++ b/modernize/fixes/fix_itertools_imports_six.py @@ -1,4 +1,4 @@ -""" Fixer for imports of itertools.(imap|ifilter|izip|ifilterfalse) """ +"""Fixer for imports of itertools.(imap|ifilter|izip|ifilterfalse)""" from __future__ import generator_stop @@ -20,9 +20,7 @@ class FixItertoolsImportsSix(fixer_base.BaseFix): BM_compatible = True PATTERN = """ import_from< 'from' 'itertools' 'import' imports=any > - """ % ( - locals() - ) + """ % (locals()) def transform(self, node, results): imports = results["imports"] diff --git a/modernize/fixes/fix_itertools_six.py b/modernize/fixes/fix_itertools_six.py index b6ff62a..3567627 100644 --- a/modernize/fixes/fix_itertools_six.py +++ b/modernize/fixes/fix_itertools_six.py @@ -1,10 +1,11 @@ -""" Fixer for itertools.(imap|ifilter|izip) --> - (six.moves.map|six.moves.filter|six.moves.zip) and - itertools.ifilterfalse --> six.moves.filterfalse (bugs 2360-2363) - imports from itertools are fixed in fix_itertools_imports_six.py - If itertools is imported as something else (ie: import itertools as it; - it.izip(spam, eggs)) method calls will not get fixed. - """ +"""Fixer for itertools.(imap|ifilter|izip) --> +(six.moves.map|six.moves.filter|six.moves.zip) and +itertools.ifilterfalse --> six.moves.filterfalse (bugs 2360-2363) +imports from itertools are fixed in fix_itertools_imports_six.py +If itertools is imported as something else (ie: import itertools as it; +it.izip(spam, eggs)) method calls will not get fixed. +""" + # This is a derived work of Lib/lib2to3/fixes/fix_itertools_import.py. That file # is under the copyright of the Python Software Foundation and licensed # under the Python Software Foundation License 2. @@ -29,9 +30,7 @@ class FixItertoolsSix(fixer_base.BaseFix): dot='.' func=%(it_funcs)s > trailer< '(' [any] ')' > > | power< func=%(it_funcs)s trailer< '(' [any] ')' > > - """ % ( - locals() - ) + """ % (locals()) # Needs to be run after fix_(map|zip|filter) run_order = 6 diff --git a/modernize/fixes/fix_metaclass.py b/modernize/fixes/fix_metaclass.py index 2bccdb9..5845d68 100644 --- a/modernize/fixes/fix_metaclass.py +++ b/modernize/fixes/fix_metaclass.py @@ -1,19 +1,20 @@ """Fixer for __metaclass__ = X -> (six.with_metaclass(X)) methods. - The various forms of classdef (inherits nothing, inherits once, inherits - many) don't parse the same in the CST, so we look at ALL classes for - a __metaclass__ and if we find one normalize the inherits to all be - an arglist. +The various forms of classdef (inherits nothing, inherits once, inherits +many) don't parse the same in the CST, so we look at ALL classes for +a __metaclass__ and if we find one normalize the inherits to all be +an arglist. - For one-liner classes ('class X: pass') there is no indent/dedent so - we normalize those into having a suite. +For one-liner classes ('class X: pass') there is no indent/dedent so +we normalize those into having a suite. - Moving the __metaclass__ into the classdef can also cause the class - body to be empty so there is some special casing for that as well. +Moving the __metaclass__ into the classdef can also cause the class +body to be empty so there is some special casing for that as well. - This fixer also tries very hard to keep original indenting and spacing - in all those corner cases. +This fixer also tries very hard to keep original indenting and spacing +in all those corner cases. """ + # This is a derived work of Lib/lib2to3/fixes/fix_metaclass.py. That file # is under the copyright of the Python Software Foundation and licensed # under the Python Software Foundation License 2. diff --git a/modernize/fixes/fix_raise.py b/modernize/fixes/fix_raise.py index 68ef28c..97ef8b6 100644 --- a/modernize/fixes/fix_raise.py +++ b/modernize/fixes/fix_raise.py @@ -17,6 +17,7 @@ any client code would have to be changed as well, we don't automate this. """ + # Author: Collin Winter, Armin Ronacher from __future__ import generator_stop diff --git a/modernize/fixes/fix_raise_six.py b/modernize/fixes/fix_raise_six.py index 54f4f7a..71b5f85 100644 --- a/modernize/fixes/fix_raise_six.py +++ b/modernize/fixes/fix_raise_six.py @@ -3,6 +3,7 @@ raise E, V, T -> six.reraise(E, V, T) """ + # Author : Markus Unterwaditzer from __future__ import generator_stop diff --git a/modernize/fixes/fix_urllib_six.py b/modernize/fixes/fix_urllib_six.py index 39733fb..05a0668 100644 --- a/modernize/fixes/fix_urllib_six.py +++ b/modernize/fixes/fix_urllib_six.py @@ -1,7 +1,8 @@ """Fix changes imports of urllib which are now incompatible. - This is a copy of Lib/lib2to3/fixes/fix_urllib.py, but modified to point to the - six.moves locations for new libraries instead of the Python 3 locations. +This is a copy of Lib/lib2to3/fixes/fix_urllib.py, but modified to point to the +six.moves locations for new libraries instead of the Python 3 locations. """ + # This is a derived work of Lib/lib2to3/fixes/fix_urllib.py. That file # is under the copyright of the Python Software Foundation and licensed # under the Python Software Foundation License 2. @@ -110,15 +111,11 @@ def build_pattern(): members = alternates(members) yield """import_name< 'import' (module={!r} | dotted_as_names< any* module={!r} any* >) > - """.format( - old_module, old_module - ) + """.format(old_module, old_module) yield """import_from< 'from' mod_member={!r} 'import' ( member={} | import_as_name< member={} 'as' any > | import_as_names< members=any* >) > - """.format( - old_module, members, members - ) + """.format(old_module, members, members) yield """import_from< 'from' module_star=%r 'import' star='*' > """ % old_module yield """import_name< 'import' @@ -126,9 +123,7 @@ def build_pattern(): """ % old_module # bare_with_attr has a special significance for FixImports.match(). yield """power< bare_with_attr={!r} trailer< '.' member={} > any* > - """.format( - old_module, members - ) + """.format(old_module, members) class FixUrllibSix(FixImports): diff --git a/modernize/main.py b/modernize/main.py index 962fbf0..5351b62 100644 --- a/modernize/main.py +++ b/modernize/main.py @@ -18,15 +18,11 @@ from . import __version__ from .fixes import fissix_fix_names, opt_in_fix_names, six_fix_names -usage = ( - __doc__ - + """\ +usage = __doc__ + """\ %s Usage: modernize [options] file|dir ... -""" - % __version__ -) +""" % __version__ def format_usage(usage): diff --git a/tests/test_fix_imports_six.py b/tests/test_fix_imports_six.py index 66df698..711945a 100644 --- a/tests/test_fix_imports_six.py +++ b/tests/test_fix_imports_six.py @@ -4,7 +4,7 @@ import unittest try: - from six.moves import tkinter + import tkinter except ImportError: tkinter = None diff --git a/tests/test_future_behaviour.py b/tests/test_future_behaviour.py index e6fba63..92a08cc 100644 --- a/tests/test_future_behaviour.py +++ b/tests/test_future_behaviour.py @@ -66,7 +66,7 @@ def _check_on_input(file_content, extra_flags=[]): try: tmpdirname = tempfile.mkdtemp() test_input_name = os.path.join(tmpdirname, "input.py") - with open(test_input_name, "wt") as input: + with open(test_input_name, "w") as input: input.write(file_content) modernize_main(extra_flags + ["-w", test_input_name]) _check_for_multiple_futures(test_input_name, file_content) @@ -94,7 +94,7 @@ def test_two_files_on_single_run(): os.path.join(tmpdirname, f"input_{idx}.py") for idx in range(0, 3) ] for input_name in input_names: - with open(input_name, "wt") as input: + with open(input_name, "w") as input: input.write(TWO_PRINTS_CONTENT) modernize_main(["-w"] + input_names) for input_name in input_names: diff --git a/tests/utils.py b/tests/utils.py index 6f84434..1c8d610 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -23,7 +23,7 @@ def check_on_input( tmpdirname = tempfile.mkdtemp() try: test_input_name = os.path.join(tmpdirname, "input.py") - with open(test_input_name, "wt") as input_file: + with open(test_input_name, "w") as input_file: input_file.write(input_content) def _check(this_input_content, which_check, check_return_code=True):