Skip to content

Commit 3afa971

Browse files
[configuration] Create a data structure to store breaking changes (#9088)
In order to be able to automate the fix later in #5462
1 parent ce8d1a9 commit 3afa971

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed

pylint/config/_breaking_changes.py

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
2+
# For details: https://github.com/pylint-dev/pylint/blob/main/LICENSE
3+
# Copyright (c) https://github.com/pylint-dev/pylint/blob/main/CONTRIBUTORS.txt
4+
5+
"""List the breaking changes in configuration files and their solutions."""
6+
7+
from __future__ import annotations
8+
9+
import enum
10+
from typing import NamedTuple
11+
12+
13+
class BreakingChange(enum.Enum):
14+
MESSAGE_MADE_DISABLED_BY_DEFAULT = "{symbol} ({msgid}) was disabled by default"
15+
MESSAGE_MADE_ENABLED_BY_DEFAULT = "{symbol} ({msgid}) was enabled by default"
16+
MESSAGE_MOVED_TO_EXTENSION = "{symbol} ({msgid}) was moved to {extension}"
17+
EXTENSION_REMOVED = "{extension} was removed"
18+
# This kind of upgrade is non-breaking but if we want to automatically upgrade it,
19+
# then we should use the message store and old_names values instead of duplicating
20+
# MESSAGE_RENAMED= "{symbol} ({msgid}) was renamed"
21+
22+
23+
class Condition(enum.Enum):
24+
MESSAGE_IS_ENABLED = "{symbol} ({msgid}) is enabled"
25+
MESSAGE_IS_NOT_ENABLED = "{symbol} ({msgid}) is not enabled"
26+
MESSAGE_IS_DISABLED = "{symbol} ({msgid}) is disabled"
27+
MESSAGE_IS_NOT_DISABLED = "{symbol} ({msgid}) is not disabled"
28+
EXTENSION_IS_LOADED = "{extension} is loaded"
29+
EXTENSION_IS_NOT_LOADED = "{extension} is not loaded"
30+
31+
32+
class Information(NamedTuple):
33+
msgid_or_symbol: str
34+
extension: str | None
35+
36+
37+
class Solution(enum.Enum):
38+
ADD_EXTENSION = "Add {extension} in 'load-plugins' option"
39+
REMOVE_EXTENSION = "Remove {extension} from the 'load-plugins' option"
40+
ENABLE_MESSAGE_EXPLICITLY = (
41+
"{symbol} ({msgid}) should be added in the 'enable' option"
42+
)
43+
ENABLE_MESSAGE_IMPLICITLY = (
44+
"{symbol} ({msgid}) should be removed from the 'disable' option"
45+
)
46+
DISABLE_MESSAGE_EXPLICITLY = (
47+
"{symbol} ({msgid}) should be added in the 'disable' option"
48+
)
49+
DISABLE_MESSAGE_IMPLICITLY = (
50+
"{symbol} ({msgid}) should be removed from the 'enable' option"
51+
)
52+
53+
54+
ConditionsToBeAffected = list[Condition]
55+
# A solution to a breaking change might imply multiple actions
56+
MultipleActionSolution = list[Solution]
57+
# Sometimes there's multiple solutions and the user needs to choose
58+
Solutions = list[MultipleActionSolution]
59+
BreakingChangeWithSolution = tuple[
60+
BreakingChange, Information, ConditionsToBeAffected, Solutions
61+
]
62+
63+
NO_SELF_USE = Information(
64+
msgid_or_symbol="no-self-use", extension="pylint.extensions.no_self_use"
65+
)
66+
COMPARE_TO_ZERO = Information(
67+
msgid_or_symbol="compare-to-zero", extension="pylint.extensions.comparetozero"
68+
)
69+
COMPARE_TO_EMPTY_STRING = Information(
70+
msgid_or_symbol="compare-to-empty-string",
71+
extension="pylint.extensions.emptystring",
72+
)
73+
74+
CONFIGURATION_BREAKING_CHANGES: dict[str, list[BreakingChangeWithSolution]] = {
75+
"2.14.0": [
76+
(
77+
BreakingChange.MESSAGE_MOVED_TO_EXTENSION,
78+
NO_SELF_USE,
79+
[Condition.MESSAGE_IS_ENABLED, Condition.EXTENSION_IS_NOT_LOADED],
80+
[[Solution.ADD_EXTENSION], [Solution.DISABLE_MESSAGE_IMPLICITLY]],
81+
),
82+
],
83+
"3.0.0": [
84+
(
85+
BreakingChange.EXTENSION_REMOVED,
86+
COMPARE_TO_ZERO,
87+
[Condition.MESSAGE_IS_NOT_DISABLED, Condition.EXTENSION_IS_LOADED],
88+
[[Solution.REMOVE_EXTENSION, Solution.ENABLE_MESSAGE_EXPLICITLY]],
89+
),
90+
(
91+
BreakingChange.EXTENSION_REMOVED,
92+
COMPARE_TO_EMPTY_STRING,
93+
[Condition.MESSAGE_IS_NOT_DISABLED, Condition.EXTENSION_IS_LOADED],
94+
[[Solution.REMOVE_EXTENSION, Solution.ENABLE_MESSAGE_EXPLICITLY]],
95+
),
96+
],
97+
}

0 commit comments

Comments
 (0)