Skip to content

Commit

Permalink
Use tomllib on Python 3.11
Browse files Browse the repository at this point in the history
  • Loading branch information
gschaffner authored and peterjc committed Dec 13, 2022
1 parent 719caa3 commit 3abee21
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
9 changes: 7 additions & 2 deletions flake8_black.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@
source code using the tool black.
"""

import sys
from os import path
from pathlib import Path

if sys.version_info >= (3, 11):
import tomllib
else:
import tomli as tomllib

import black
import tomli

from flake8 import utils as stdin_utils
from flake8 import LOG
Expand Down Expand Up @@ -58,7 +63,7 @@ def load_black_mode(toml_filename=None):
LOG.info("flake8-black: loading black settings from %s", toml_filename)
try:
with toml_filename.open(mode="rb") as toml_file:
pyproject_toml = tomli.load(toml_file)
pyproject_toml = tomllib.load(toml_file)
except ValueError:
LOG.info("flake8-black: invalid TOML file %s", toml_filename)
raise BadBlackConfig(path.relpath(toml_filename))
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ requires-python = '>=3.7'
dependencies = [
'flake8>=3',
'black>=22.1.0',
'tomli',
'tomli ; python_version < "3.11"',
]
dynamic = ['version']
[project.entry-points]
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ flake8 >= 3.0.0

# We need black, which in turn needs Python 3.6+
black
tomli
tomli ; python_version < "3.11"

0 comments on commit 3abee21

Please sign in to comment.