Skip to content
This repository was archived by the owner on Nov 3, 2023. It is now read-only.

Commit 4fb964b

Browse files
committed
Use tomllib/tomli for reading .toml configs
Use the built-in `tomllib` module in Python 3.11 and the modern `tomli` package in older Python versions to read .toml configs instead of the unmaintained and broken `toml` package. Fixes #599 Fixes #600
1 parent a6fe422 commit 4fb964b

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
lines changed

requirements/runtime.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
snowballstemmer==1.2.1
2-
toml==0.10.2
2+
tomli==2.0.1; python_version < "3.11"

requirements/tests.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@ pytest==6.2.5
22
mypy==0.930
33
black==22.3
44
isort==5.4.2
5-
types-toml
65
types-setuptools

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
'snowballstemmer',
99
]
1010
extra_requirements = {
11-
'toml': ['toml'],
11+
'toml': ['tomli; python_version < "3.11"'],
1212
}
1313

1414

src/pydocstyle/config.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import itertools
55
import operator
66
import os
7+
import sys
78
from collections import namedtuple
89
from collections.abc import Set
910
from configparser import NoOptionError, NoSectionError, RawConfigParser
@@ -13,10 +14,13 @@
1314
from .utils import __version__, log
1415
from .violations import ErrorRegistry, conventions
1516

16-
try:
17-
import toml
18-
except ImportError: # pragma: no cover
19-
toml = None # type: ignore
17+
if sys.version_info >= (3, 11):
18+
import tomllib
19+
else:
20+
try:
21+
import tomli as tomllib
22+
except ImportError: # pragma: no cover
23+
tomllib = None # type: ignore
2024

2125

2226
def check_initialized(method):
@@ -59,15 +63,15 @@ def read(self, filenames, encoding=None):
5963
read_ok = []
6064
for filename in filenames:
6165
try:
62-
with open(filename, encoding=encoding) as fp:
63-
if not toml:
66+
with open(filename, "rb") as fp:
67+
if not tomllib:
6468
log.warning(
6569
"The %s configuration file was ignored, "
66-
"because the `toml` package is not installed.",
70+
"because the `tomli` package is not installed.",
6771
filename,
6872
)
6973
continue
70-
self._config.update(toml.load(fp))
74+
self._config.update(tomllib.load(fp))
7175
except OSError:
7276
continue
7377
if isinstance(filename, os.PathLike):

0 commit comments

Comments
 (0)