diff --git a/autoflake.py b/autoflake.py index bf15d2d..84521f2 100755 --- a/autoflake.py +++ b/autoflake.py @@ -1089,9 +1089,13 @@ def find_files(filenames, recursive, exclude): def process_pyproject_toml(toml_file_path): """Extract config mapping from pyproject.toml file.""" - import toml + try: + import tomllib + except ModuleNotFoundError: + import tomli as tomllib - return toml.load(toml_file_path).get("tool", {}).get("autoflake", None) + with open(toml_file_path, "rb") as f: + return tomllib.load(f).get("tool", {}).get("autoflake", None) def process_setup_cfg(cfg_file_path): diff --git a/setup.cfg b/setup.cfg index 13c0a7a..1a31da5 100644 --- a/setup.cfg +++ b/setup.cfg @@ -22,7 +22,7 @@ py_modules = autoflake install_requires = pyflakes>=1.1.0 - toml>=0.10.2 + tomli>=2.0.1;python_version<'3.11' python_requires = >=3.7 test_suite = test_autoflake