eric7/DebugClients/Python/coverage/tomlconfig.py

branch
eric7
changeset 9099
0e511e0e94a3
parent 8929
fcca2fa618bf
diff -r fb9351497cea -r 0e511e0e94a3 eric7/DebugClients/Python/coverage/tomlconfig.py
--- a/eric7/DebugClients/Python/coverage/tomlconfig.py	Tue May 24 10:22:46 2022 +0200
+++ b/eric7/DebugClients/Python/coverage/tomlconfig.py	Tue May 24 11:00:52 2022 +0200
@@ -7,15 +7,21 @@
 import os
 import re
 
+from coverage import env
 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 env.PYVERSION >= (3, 11):
+    import tomllib      # pylint: disable=import-error
+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
+    tomllib = import_third_party("tomli")
 
 
 class TomlDecodeError(Exception):
@@ -45,11 +51,11 @@
                 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:

eric ide

mercurial