From 3abee21d6f3928ccef4832bbb0ead980b2f02270 Mon Sep 17 00:00:00 2001 From: Ganden Schaffner Date: Mon, 12 Dec 2022 00:00:00 -0800 Subject: [PATCH] Use tomllib on Python 3.11 --- flake8_black.py | 9 +++++++-- pyproject.toml | 2 +- requirements.txt | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/flake8_black.py b/flake8_black.py index 35e3b51..9ef2e0c 100644 --- a/flake8_black.py +++ b/flake8_black.py @@ -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 @@ -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)) diff --git a/pyproject.toml b/pyproject.toml index 07ca9fc..64a3b0c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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] diff --git a/requirements.txt b/requirements.txt index 3326334..5851f03 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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"