summaryrefslogtreecommitdiffstats
path: root/pre_commit_hooks/check_toml.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2022-06-19 07:03:36 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2022-06-19 07:03:44 +0000
commit9262e31316a16180044e0e28a2740238f8aef5c4 (patch)
tree49b2bc070018965707ec237623da9932c880fae4 /pre_commit_hooks/check_toml.py
parentAdding debian version 4.1.0-1. (diff)
downloadpre-commit-hooks-9262e31316a16180044e0e28a2740238f8aef5c4.tar.xz
pre-commit-hooks-9262e31316a16180044e0e28a2740238f8aef5c4.zip
Merging upstream version 4.3.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'pre_commit_hooks/check_toml.py')
-rw-r--r--pre_commit_hooks/check_toml.py16
1 files changed, 11 insertions, 5 deletions
diff --git a/pre_commit_hooks/check_toml.py b/pre_commit_hooks/check_toml.py
index f623e68..0407371 100644
--- a/pre_commit_hooks/check_toml.py
+++ b/pre_commit_hooks/check_toml.py
@@ -1,11 +1,16 @@
+from __future__ import annotations
+
import argparse
-from typing import Optional
+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: Optional[Sequence[str]] = None) -> int:
+def main(argv: Sequence[str] | None = None) -> int:
parser = argparse.ArgumentParser()
parser.add_argument('filenames', nargs='*', help='Filenames to check.')
args = parser.parse_args(argv)
@@ -13,8 +18,9 @@ def main(argv: Optional[Sequence[str]] = 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