diff options
Diffstat (limited to 'coverage/tomlconfig.py')
-rw-r--r-- | coverage/tomlconfig.py | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/coverage/tomlconfig.py b/coverage/tomlconfig.py index a06da65f..82f84ce9 100644 --- a/coverage/tomlconfig.py +++ b/coverage/tomlconfig.py @@ -6,16 +6,21 @@ import configparser import os import re +import sys from coverage.exceptions import ConfigError from coverage.misc import import_third_party, substitute_variables -# TOML support is an install-time extra option. (Import typing is here because -# 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 +else: + # TOML support on Python 3.10 and below is an install-time extra option. + # (Import typing is here because 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 + tomllib = import_third_party("tomli") class TomlDecodeError(Exception): @@ -45,11 +50,11 @@ class TomlConfigParser: toml_text = fp.read() except OSError: return [] - if tomli is not None: + if tomllib is not None: toml_text = substitute_variables(toml_text, os.environ) try: - self.data = tomli.loads(toml_text) - except tomli.TOMLDecodeError as err: + self.data = tomllib.loads(toml_text) + except tomllib.TOMLDecodeError as err: raise TomlDecodeError(str(err)) from err return [filename] else: |