From fc88f3fa495385e6b367f7c4c8cf10940ad053da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Noord?= <13665637+DanielNoord@users.noreply.github.com> Date: Tue, 24 May 2022 08:44:13 +0200 Subject: [PATCH] Use tomli and tomllib instead of toml --- pre_commit_hooks/check_toml.py | 11 ++++++++--- setup.cfg | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/pre_commit_hooks/check_toml.py b/pre_commit_hooks/check_toml.py index 88f70865..0407371e 100644 --- a/pre_commit_hooks/check_toml.py +++ b/pre_commit_hooks/check_toml.py @@ -1,9 +1,13 @@ from __future__ import annotations import argparse +import sys from typing import Sequence -import toml +if sys.version_info >= (3, 11): # pragma: >=3.11 cover + import tomllib +else: # pragma: <3.11 cover + import tomli as tomllib def main(argv: Sequence[str] | None = None) -> int: @@ -14,8 +18,9 @@ def main(argv: Sequence[str] | None = None) -> int: retval = 0 for filename in args.filenames: try: - toml.load(filename) - except toml.TomlDecodeError as exc: + with open(filename, mode='rb') as fp: + tomllib.load(fp) + except tomllib.TOMLDecodeError as exc: print(f'{filename}: {exc}') retval = 1 return retval diff --git a/setup.cfg b/setup.cfg index 8247f311..0f249c13 100644 --- a/setup.cfg +++ b/setup.cfg @@ -24,7 +24,7 @@ classifiers = packages = find: install_requires = ruamel.yaml>=0.15 - toml + tomli>=1.1.0;python_version<"3.11" python_requires = >=3.7 [options.packages.find]