From eddf8fafdd4d314c404af9f77fb3d4811b883ba7 Mon Sep 17 00:00:00 2001 From: Hideo Hattori Date: Sun, 17 Mar 2024 22:05:21 +0900 Subject: [PATCH] fix: repeated autopep8 use in runpy by reloading pycodestyle with importlib --- autopep8.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/autopep8.py b/autopep8.py index 792a5016..ff0e97e6 100755 --- a/autopep8.py +++ b/autopep8.py @@ -69,6 +69,7 @@ class documentation for more information. import copy import difflib import fnmatch +import importlib import inspect import io import itertools @@ -221,9 +222,6 @@ def extended_blank_lines(logical_line, yield (0, 'E301 expected 1 blank line, found 0') -pycodestyle.register_check(extended_blank_lines) - - def continued_indentation(logical_line, tokens, indent_level, hang_closing, indent_char, noqa): """Override pycodestyle's function to provide indentation information.""" @@ -415,7 +413,11 @@ def continued_indentation(logical_line, tokens, indent_level, hang_closing, yield (pos, 'E125 {}'.format(desired_indent)) +# NOTE: need reload with runpy and call twice +# see: https://github.com/hhatto/autopep8/issues/625 +importlib.reload(pycodestyle) del pycodestyle._checks['logical_line'][pycodestyle.continued_indentation] +pycodestyle.register_check(extended_blank_lines) pycodestyle.register_check(continued_indentation)