summaryrefslogtreecommitdiffstats
path: root/pre_commit_hooks/check_toml.py
diff options
context:
space:
mode:
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