summaryrefslogtreecommitdiff
path: root/dev-python/pydocstyle/files/pydocstyle-6.2.0-tomli.patch
blob: f7600d1973bb02cccaeca1463209c8a3d1c1f586 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
From b45a393b2f0c4ce0f17c3e58cf5d768bd653e155 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= <mgorny@gentoo.org>
Date: Tue, 3 Jan 2023 06:49:32 +0100
Subject: [PATCH] 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
---
 docs/release_notes.rst   |  7 +++++++
 poetry.lock              | 16 ++++++++--------
 pyproject.toml           |  4 ++--
 requirements/runtime.txt |  2 +-
 requirements/tests.txt   |  1 -
 src/pydocstyle/config.py | 20 ++++++++++++--------
 6 files changed, 30 insertions(+), 20 deletions(-)

diff --git a/pyproject.toml b/pyproject.toml
index 607aa3f..84bfe0d 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -21,11 +21,11 @@ classifiers = [
 [tool.poetry.dependencies]
 python = ">=3.6"
 snowballstemmer = ">=2.2.0"
-toml = {version = ">=0.10.2", optional = true}
+tomli = {version = ">=1.2.3", optional = true, python = "<3.11"}
 importlib-metadata = {version = ">=2.0.0,<5.0.0", python = "<3.8"}
 
 [tool.poetry.extras]
-toml = ["toml"]
+toml = ["tomli"]
 
 [tool.poetry.scripts]
 pydocstyle = "pydocstyle.cli:main"
diff --git a/src/pydocstyle/config.py b/src/pydocstyle/config.py
index 4819cde..c05f7dc 100644
--- a/src/pydocstyle/config.py
+++ b/src/pydocstyle/config.py
@@ -4,6 +4,7 @@ import copy
 import itertools
 import operator
 import os
+import sys
 from collections import namedtuple
 from collections.abc import Set
 from configparser import NoOptionError, NoSectionError, RawConfigParser
@@ -14,10 +15,13 @@ from ._version import __version__
 from .utils import 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):
@@ -60,15 +64,15 @@ class TomlParser:
         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):
-- 
2.39.0