Skip to content

Commit 2b6a486

Browse files
authored
Merge pull request #771 from DanielNoord/tomli
Use tomli and tomllib instead of toml
2 parents 6a5ae70 + fc88f3f commit 2b6a486

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

pre_commit_hooks/check_toml.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
from __future__ import annotations
22

33
import argparse
4+
import sys
45
from typing import Sequence
56

6-
import toml
7+
if sys.version_info >= (3, 11): # pragma: >=3.11 cover
8+
import tomllib
9+
else: # pragma: <3.11 cover
10+
import tomli as tomllib
711

812

913
def main(argv: Sequence[str] | None = None) -> int:
@@ -14,8 +18,9 @@ def main(argv: Sequence[str] | None = None) -> int:
1418
retval = 0
1519
for filename in args.filenames:
1620
try:
17-
toml.load(filename)
18-
except toml.TomlDecodeError as exc:
21+
with open(filename, mode='rb') as fp:
22+
tomllib.load(fp)
23+
except tomllib.TOMLDecodeError as exc:
1924
print(f'{filename}: {exc}')
2025
retval = 1
2126
return retval

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ classifiers =
2424
packages = find:
2525
install_requires =
2626
ruamel.yaml>=0.15
27-
toml
27+
tomli>=1.1.0;python_version<"3.11"
2828
python_requires = >=3.7
2929

3030
[options.packages.find]

0 commit comments

Comments
 (0)