Skip to content

Commit

Permalink
Merge pull request #771 from DanielNoord/tomli
Browse files Browse the repository at this point in the history
Use tomli and tomllib instead of toml
  • Loading branch information
asottile authored May 31, 2022
2 parents 6a5ae70 + fc88f3f commit 2b6a486
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions pre_commit_hooks/check_toml.py
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 2b6a486

Please sign in to comment.