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

Commit 3bc3b87

Browse files
mgornysambhav
andauthored
Use tomllib/tomli for reading .toml configs (#608)
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 Co-authored-by: Sambhav Kothari <[email protected]>
1 parent 5c55802 commit 3bc3b87

File tree

6 files changed

+30
-20
lines changed

6 files changed

+30
-20
lines changed

docs/release_notes.rst

+7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ Release Notes
55
`Semantic Versioning <http://semver.org/>`_ specification.
66

77

8+
Current Development Version
9+
---------------------------
10+
11+
Bug Fixes
12+
13+
* Use tomllib/tomli to correctly read .toml files (#599, #600).
14+
815
6.2.0 - January 2nd, 2023
916
---------------------------
1017

poetry.lock

+8-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ classifiers = [
2121
[tool.poetry.dependencies]
2222
python = ">=3.6"
2323
snowballstemmer = ">=2.2.0"
24-
toml = {version = ">=0.10.2", optional = true}
24+
tomli = {version = ">=1.2.3", optional = true, python = "<3.11"}
2525
importlib-metadata = {version = ">=2.0.0,<5.0.0", python = "<3.8"}
2626

2727
[tool.poetry.extras]
28-
toml = ["toml"]
28+
toml = ["tomli"]
2929

3030
[tool.poetry.scripts]
3131
pydocstyle = "pydocstyle.cli:main"

requirements/runtime.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
snowballstemmer>=1.2.1
2-
toml>=0.10.2
2+
tomli>=1.2.3; python_version < "3.11"
33
importlib-metadata<5.0.0,>=2.0.0; python_version < "3.8"

requirements/tests.txt

-1
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

src/pydocstyle/config.py

+12-8
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
@@ -14,10 +15,13 @@
1415
from .utils import log
1516
from .violations import ErrorRegistry, conventions
1617

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

2226

2327
def check_initialized(method):
@@ -60,15 +64,15 @@ def read(self, filenames, encoding=None):
6064
read_ok = []
6165
for filename in filenames:
6266
try:
63-
with open(filename, encoding=encoding) as fp:
64-
if not toml:
67+
with open(filename, "rb") as fp:
68+
if not tomllib:
6569
log.warning(
6670
"The %s configuration file was ignored, "
67-
"because the `toml` package is not installed.",
71+
"because the `tomli` package is not installed.",
6872
filename,
6973
)
7074
continue
71-
self._config.update(toml.load(fp))
75+
self._config.update(tomllib.load(fp))
7276
except OSError:
7377
continue
7478
if isinstance(filename, os.PathLike):

0 commit comments

Comments
 (0)