From a941cf615e06b896c254964b8cdf391889252e82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Date: Fri, 28 Oct 2022 07:51:56 +0200 Subject: [PATCH] Support using built-in tomllib in Python 3.11 --- autopep8.py | 9 ++++++--- setup.py | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/autopep8.py b/autopep8.py index a734d2b3..87dc7403 100755 --- a/autopep8.py +++ b/autopep8.py @@ -4046,13 +4046,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 +4064,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) diff --git a/setup.py b/setup.py index 4849574a..1dfb335c 100755 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ INSTALL_REQUIRES = ( - ['pycodestyle >= 2.9.1', 'tomli'] + ['pycodestyle >= 2.9.1', 'tomli; python_version < "3.11"'] )