From 74ee033f6adf9c8efef1033ac3a3bd56a55a2437 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20Gr=C3=B6nholm?= Date: Mon, 16 May 2022 00:20:35 +0300 Subject: [PATCH] Use tomllib instead of tomli on Python 3.11 The "toml" extra should not cause tomli to be installed on 3.11. --- CHANGES.rst | 3 ++- CONTRIBUTORS.txt | 1 + coverage/tomlconfig.py | 8 ++++++-- setup.py | 2 +- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 13d3846ce..411cb0368 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -20,7 +20,8 @@ development at the same time, such as 4.5.x and 5.0. Unreleased ---------- -Nothing yet. +- The ``toml`` extra no longer installs ``tomli`` on Python 3.11 (``tomllib`` + is used instead) .. _changes_633: diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index 360635797..91fe056cd 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -11,6 +11,7 @@ Albertas Agejevas Aleksi Torhamo Alex Gaynor Alex Groce +Alex Grönholm Alex Sandro Alexander Todorov Alexander Walters diff --git a/coverage/tomlconfig.py b/coverage/tomlconfig.py index a06da65f7..b7969cbb5 100644 --- a/coverage/tomlconfig.py +++ b/coverage/tomlconfig.py @@ -6,6 +6,7 @@ import configparser import os import re +import sys from coverage.exceptions import ConfigError from coverage.misc import import_third_party, substitute_variables @@ -14,8 +15,11 @@ # import_third_party will unload any module that wasn't already imported. # tomli imports typing, and if we unload it, later it's imported again, and on # Python 3.6, this causes infinite recursion.) -import typing # pylint: disable=unused-import, wrong-import-order -tomli = import_third_party("tomli") +if sys.version_info >= (3, 11): + import tomllib as tomli +else: + import typing # pylint: disable=unused-import, wrong-import-order + tomli = import_third_party("tomli") class TomlDecodeError(Exception): diff --git a/setup.py b/setup.py index 46f764dab..68f894de1 100644 --- a/setup.py +++ b/setup.py @@ -108,7 +108,7 @@ def better_set_verbosity(v): extras_require={ # Enable pyproject.toml support. - 'toml': ['tomli'], + 'toml; python_version < "3.11"': ['tomli'], }, # We need to get HTML assets from our htmlfiles directory.