Skip to content

Commit 1be986d

Browse files
committed
fix: tomllib name error when not supported
1 parent 864c461 commit 1be986d

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

radon/cli/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99
try:
1010
# Python 3.11+
1111
import tomllib
12+
TOMLLIB_PRESENT = True
1213
except ImportError:
1314
try:
14-
# Support for python <3.11
15+
# Support for Python <3.11
1516
import tomli as tomllib
17+
TOMLLIB_PRESENT = True
1618
except ImportError:
17-
pass
19+
TOMLLIB_PRESENT = False
1820

1921
import radon.complexity as cc_mod
2022
from radon.cli.colors import BRIGHT, RED, RESET
@@ -60,6 +62,9 @@ def get_value(self, key, type, default):
6062

6163
@staticmethod
6264
def toml_config():
65+
if not TOMLLIB_PRESENT:
66+
return {}
67+
6368
try:
6469
with open("pyproject.toml", "rb") as pyproject_file:
6570
pyproject = tomllib.load(pyproject_file)

0 commit comments

Comments
 (0)