diff --git a/autopep8.py b/autopep8.py index 03cf8c35..1534a7a7 100755 --- a/autopep8.py +++ b/autopep8.py @@ -84,7 +84,6 @@ 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 @@ -758,16 +757,14 @@ 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( - operator_whitespace(fixed, ts)) + try: + _missing_whitespace = ( + pycodestyle.missing_whitespace_around_operator + ) + except AttributeError: + # pycodestyle >= 2.11.0 + _missing_whitespace = pycodestyle.missing_whitespace + errors = list(_missing_whitespace(fixed, ts)) for e in reversed(errors): if error_code != e[1].split()[0]: continue