Skip to content

Commit ce51a72

Browse files
committed
Disable more pylint checks that are also checked by mypy
pylint has some false positive for these checks, so better to just rely on mypy for them. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 9664699 commit ce51a72

File tree

8 files changed

+60
-20
lines changed

8 files changed

+60
-20
lines changed

cookiecutter/migrate.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,42 @@ def replace_file_contents_atomically( # noqa; DOC501
9393
raise
9494

9595

96+
def add_pylint_checks() -> None:
97+
"""Add new pylint checks to the project."""
98+
pyproject_toml = Path("pyproject.toml")
99+
print(
100+
f"{pyproject_toml}: Skip some flaky pylint checks that are checked better by mypy."
101+
)
102+
marker = ' "no-member",\n'
103+
pyproject_toml_content = pyproject_toml.read_text(encoding="utf-8")
104+
if pyproject_toml_content.find(marker) == -1:
105+
manual_step(
106+
f"""\
107+
{pyproject_toml}: We couldn't find the marker {marker!r} in the file.
108+
Please add the following lines to the file manually in the
109+
`[tool.pylint.messages_control]` section, under the `disable` key (ideally below other
110+
checks that are disabled because `mypy` already checks them) if they are missing:
111+
"no-name-in-module",
112+
"possibly-used-before-assignment",
113+
"""
114+
)
115+
return
116+
117+
replacement = ""
118+
if pyproject_toml_content.find("possibly-used-before-assignment") == -1:
119+
replacement += ' "possibly-used-before-assignment",\n'
120+
if pyproject_toml_content.find("no-name-in-module") == -1:
121+
replacement += ' "no-name-in-module",\n'
122+
123+
if not replacement:
124+
print(f"{pyproject_toml}: seems to be already up-to-date.")
125+
return
126+
127+
replace_file_contents_atomically(
128+
pyproject_toml, marker, marker + replacement, content=pyproject_toml_content
129+
)
130+
131+
96132
def main() -> None:
97133
"""Run the migration steps."""
98134
# Dependabot patch
@@ -129,6 +165,9 @@ def main() -> None:
129165
)
130166
print("=" * 72)
131167

168+
# Add new pylint checks
169+
add_pylint_checks()
170+
132171
# Add a separation line like this one after each migration step.
133172
print("=" * 72)
134173

cookiecutter/{{cookiecutter.github_repo_name}}/pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,11 @@ disable = [
178178
# disabled because it conflicts with isort
179179
"wrong-import-order",
180180
"ungrouped-imports",
181-
# pylint's unsubscriptable check is buggy and is not needed because
182-
# it is a type-check, for which we already have mypy.
181+
# Checked by mypy (and pylint is very flaky checking these)
183182
"unsubscriptable-object",
184-
# Checked by mypy
185183
"no-member",
184+
"no-name-in-module",
185+
"possibly-used-before-assignment",
186186
# Checked by flake8
187187
"f-string-without-interpolation",
188188
"line-too-long",

pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,11 @@ disable = [
161161
# disabled because it conflicts with isort
162162
"wrong-import-order",
163163
"ungrouped-imports",
164-
# pylint's unsubscriptable check is buggy and is not needed because
165-
# it is a type-check, for which we already have mypy.
164+
# Checked by mypy (and pylint is very flaky checking these)
166165
"unsubscriptable-object",
167166
"no-member",
167+
"no-name-in-module",
168+
"possibly-used-before-assignment",
168169
# Checked by flake8
169170
"f-string-without-interpolation",
170171
"line-too-long",

tests_golden/integration/test_cookiecutter_generation/actor/frequenz-actor-test/pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,11 @@ disable = [
137137
# disabled because it conflicts with isort
138138
"wrong-import-order",
139139
"ungrouped-imports",
140-
# pylint's unsubscriptable check is buggy and is not needed because
141-
# it is a type-check, for which we already have mypy.
140+
# Checked by mypy (and pylint is very flaky checking these)
142141
"unsubscriptable-object",
143-
# Checked by mypy
144142
"no-member",
143+
"no-name-in-module",
144+
"possibly-used-before-assignment",
145145
# Checked by flake8
146146
"f-string-without-interpolation",
147147
"line-too-long",

tests_golden/integration/test_cookiecutter_generation/api/frequenz-api-test/pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,11 @@ disable = [
145145
# disabled because it conflicts with isort
146146
"wrong-import-order",
147147
"ungrouped-imports",
148-
# pylint's unsubscriptable check is buggy and is not needed because
149-
# it is a type-check, for which we already have mypy.
148+
# Checked by mypy (and pylint is very flaky checking these)
150149
"unsubscriptable-object",
151-
# Checked by mypy
152150
"no-member",
151+
"no-name-in-module",
152+
"possibly-used-before-assignment",
153153
# Checked by flake8
154154
"f-string-without-interpolation",
155155
"line-too-long",

tests_golden/integration/test_cookiecutter_generation/app/frequenz-app-test/pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,11 @@ disable = [
136136
# disabled because it conflicts with isort
137137
"wrong-import-order",
138138
"ungrouped-imports",
139-
# pylint's unsubscriptable check is buggy and is not needed because
140-
# it is a type-check, for which we already have mypy.
139+
# Checked by mypy (and pylint is very flaky checking these)
141140
"unsubscriptable-object",
142-
# Checked by mypy
143141
"no-member",
142+
"no-name-in-module",
143+
"possibly-used-before-assignment",
144144
# Checked by flake8
145145
"f-string-without-interpolation",
146146
"line-too-long",

tests_golden/integration/test_cookiecutter_generation/lib/frequenz-test-python/pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,11 @@ disable = [
133133
# disabled because it conflicts with isort
134134
"wrong-import-order",
135135
"ungrouped-imports",
136-
# pylint's unsubscriptable check is buggy and is not needed because
137-
# it is a type-check, for which we already have mypy.
136+
# Checked by mypy (and pylint is very flaky checking these)
138137
"unsubscriptable-object",
139-
# Checked by mypy
140138
"no-member",
139+
"no-name-in-module",
140+
"possibly-used-before-assignment",
141141
# Checked by flake8
142142
"f-string-without-interpolation",
143143
"line-too-long",

tests_golden/integration/test_cookiecutter_generation/model/frequenz-model-test/pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,11 @@ disable = [
137137
# disabled because it conflicts with isort
138138
"wrong-import-order",
139139
"ungrouped-imports",
140-
# pylint's unsubscriptable check is buggy and is not needed because
141-
# it is a type-check, for which we already have mypy.
140+
# Checked by mypy (and pylint is very flaky checking these)
142141
"unsubscriptable-object",
143-
# Checked by mypy
144142
"no-member",
143+
"no-name-in-module",
144+
"possibly-used-before-assignment",
145145
# Checked by flake8
146146
"f-string-without-interpolation",
147147
"line-too-long",

0 commit comments

Comments
 (0)