From 028f68f81ee4b29111b3b1814d53476dfc91d78f Mon Sep 17 00:00:00 2001 From: Kajsa Eriksson Rosenqvist Date: Fri, 4 Aug 2023 12:09:34 +0100 Subject: [PATCH] Version dependent operator whitespace function. --- autopep8.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/autopep8.py b/autopep8.py index 5e2a9fda..727b1cc0 100755 --- a/autopep8.py +++ b/autopep8.py @@ -84,6 +84,7 @@ class documentation for more information. import warnings import ast from configparser import ConfigParser as SafeConfigParser, Error +from packaging.version import parse as parse_version import pycodestyle from pycodestyle import STARTSWITH_INDENT_STATEMENT_REGEX @@ -757,8 +758,16 @@ def fix_e225(self, result): return if not check_syntax(fixed.lstrip()): return + if ( + parse_version(pycodestyle.__version__) >= + parse_version("2.11.0") + ): + operator_whitespace = pycodestyle.missing_whitespace + else: + operator_whitespace = \ + pycodestyle.missing_whitespace_around_operator errors = list( - pycodestyle.missing_whitespace_around_operator(fixed, ts)) + operator_whitespace(fixed, ts)) for e in reversed(errors): if error_code != e[1].split()[0]: continue