diff --git a/docs/release_notes.rst b/docs/release_notes.rst index a9060ae..cfdfb61 100644 --- a/docs/release_notes.rst +++ b/docs/release_notes.rst @@ -18,6 +18,7 @@ New Features Bug Fixes * Fix ``--match`` option to only consider filename when matching full paths (#550). +* Use tomllib/tomli to correctly read .toml files (#599, #600). 6.1.1 - May 17th, 2021 --------------------------- diff --git a/requirements/runtime.txt b/requirements/runtime.txt index 8030275..b4e9ca7 100644 --- a/requirements/runtime.txt +++ b/requirements/runtime.txt @@ -1,2 +1,2 @@ snowballstemmer==1.2.1 -toml==0.10.2 +tomli==2.0.1; python_version < "3.11" diff --git a/requirements/tests.txt b/requirements/tests.txt index ed12797..f236d68 100644 --- a/requirements/tests.txt +++ b/requirements/tests.txt @@ -2,5 +2,4 @@ pytest==6.2.5 mypy==0.930 black==22.3 isort==5.4.2 -types-toml types-setuptools diff --git a/setup.py b/setup.py index a9c5df1..6c0671c 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ 'snowballstemmer', ] extra_requirements = { - 'toml': ['toml'], + 'toml': ['tomli; python_version < "3.11"'], } diff --git a/src/pydocstyle/config.py b/src/pydocstyle/config.py index ed00c87..db7ed1b 100644 --- a/src/pydocstyle/config.py +++ b/src/pydocstyle/config.py @@ -4,6 +4,7 @@ import itertools import operator import os +import sys from collections import namedtuple from collections.abc import Set from configparser import NoOptionError, NoSectionError, RawConfigParser @@ -13,10 +14,13 @@ from .utils import __version__, log from .violations import ErrorRegistry, conventions -try: - import toml -except ImportError: # pragma: no cover - toml = None # type: ignore +if sys.version_info >= (3, 11): + import tomllib +else: + try: + import tomli as tomllib + except ImportError: # pragma: no cover + tomllib = None # type: ignore def check_initialized(method): @@ -59,15 +63,15 @@ def read(self, filenames, encoding=None): read_ok = [] for filename in filenames: try: - with open(filename, encoding=encoding) as fp: - if not toml: + with open(filename, "rb") as fp: + if not tomllib: log.warning( "The %s configuration file was ignored, " - "because the `toml` package is not installed.", + "because the `tomli` package is not installed.", filename, ) continue - self._config.update(toml.load(fp)) + self._config.update(tomllib.load(fp)) except OSError: continue if isinstance(filename, os.PathLike):