diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 4ba81ec9..9190bdad 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -27,6 +27,7 @@ * Change `edit_uri` default branch to v0.x.x in mkdocs.yml. * Added a new default option `asyncio_default_fixture_loop_scope = "function"` for `pytest-asyncio` as not providing a value is deprecated. * The migration script is now written in Python, so it should be (hopefully) more compatible with different OSes. +* Disable more `pylint` checks that are also checked by `mypy` to avoid false positives. ## Bug Fixes diff --git a/cookiecutter/migrate.py b/cookiecutter/migrate.py index e2b45b76..1fdae3e5 100644 --- a/cookiecutter/migrate.py +++ b/cookiecutter/migrate.py @@ -92,6 +92,42 @@ def replace_file_contents_atomically( # noqa; DOC501 raise +def add_pylint_checks() -> None: + """Add new pylint checks to the project.""" + pyproject_toml = Path("pyproject.toml") + print( + f"{pyproject_toml}: Skip some flaky pylint checks that are checked better by mypy." + ) + marker = ' "no-member",\n' + pyproject_toml_content = pyproject_toml.read_text(encoding="utf-8") + if pyproject_toml_content.find(marker) == -1: + manual_step( + f"""\ +{pyproject_toml}: We couldn't find the marker {marker!r} in the file. +Please add the following lines to the file manually in the +`[tool.pylint.messages_control]` section, under the `disable` key (ideally below other +checks that are disabled because `mypy` already checks them) if they are missing: + "no-name-in-module", + "possibly-used-before-assignment", +""" + ) + return + + replacement = "" + if pyproject_toml_content.find("possibly-used-before-assignment") == -1: + replacement += ' "possibly-used-before-assignment",\n' + if pyproject_toml_content.find("no-name-in-module") == -1: + replacement += ' "no-name-in-module",\n' + + if not replacement: + print(f"{pyproject_toml}: seems to be already up-to-date.") + return + + replace_file_contents_atomically( + pyproject_toml, marker, marker + replacement, content=pyproject_toml_content + ) + + def main() -> None: """Run the migration steps.""" # Dependabot patch @@ -128,6 +164,9 @@ def main() -> None: ) print("=" * 72) + # Add new pylint checks + add_pylint_checks() + # Add a separation line like this one after each migration step. print("=" * 72) diff --git a/cookiecutter/{{cookiecutter.github_repo_name}}/pyproject.toml b/cookiecutter/{{cookiecutter.github_repo_name}}/pyproject.toml index b185b57d..56a43e38 100644 --- a/cookiecutter/{{cookiecutter.github_repo_name}}/pyproject.toml +++ b/cookiecutter/{{cookiecutter.github_repo_name}}/pyproject.toml @@ -178,11 +178,11 @@ disable = [ # disabled because it conflicts with isort "wrong-import-order", "ungrouped-imports", - # pylint's unsubscriptable check is buggy and is not needed because - # it is a type-check, for which we already have mypy. + # Checked by mypy (and pylint is very flaky checking these) "unsubscriptable-object", - # Checked by mypy "no-member", + "no-name-in-module", + "possibly-used-before-assignment", # Checked by flake8 "f-string-without-interpolation", "line-too-long", diff --git a/pyproject.toml b/pyproject.toml index e142361d..3c089b67 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -167,10 +167,11 @@ disable = [ # disabled because it conflicts with isort "wrong-import-order", "ungrouped-imports", - # pylint's unsubscriptable check is buggy and is not needed because - # it is a type-check, for which we already have mypy. + # Checked by mypy (and pylint is very flaky checking these) "unsubscriptable-object", "no-member", + "no-name-in-module", + "possibly-used-before-assignment", # Checked by flake8 "f-string-without-interpolation", "line-too-long", diff --git a/tests_golden/integration/test_cookiecutter_generation/actor/frequenz-actor-test/pyproject.toml b/tests_golden/integration/test_cookiecutter_generation/actor/frequenz-actor-test/pyproject.toml index 6d93d7ee..a8cee941 100644 --- a/tests_golden/integration/test_cookiecutter_generation/actor/frequenz-actor-test/pyproject.toml +++ b/tests_golden/integration/test_cookiecutter_generation/actor/frequenz-actor-test/pyproject.toml @@ -137,11 +137,11 @@ disable = [ # disabled because it conflicts with isort "wrong-import-order", "ungrouped-imports", - # pylint's unsubscriptable check is buggy and is not needed because - # it is a type-check, for which we already have mypy. + # Checked by mypy (and pylint is very flaky checking these) "unsubscriptable-object", - # Checked by mypy "no-member", + "no-name-in-module", + "possibly-used-before-assignment", # Checked by flake8 "f-string-without-interpolation", "line-too-long", diff --git a/tests_golden/integration/test_cookiecutter_generation/api/frequenz-api-test/pyproject.toml b/tests_golden/integration/test_cookiecutter_generation/api/frequenz-api-test/pyproject.toml index be149273..4f943ce6 100644 --- a/tests_golden/integration/test_cookiecutter_generation/api/frequenz-api-test/pyproject.toml +++ b/tests_golden/integration/test_cookiecutter_generation/api/frequenz-api-test/pyproject.toml @@ -145,11 +145,11 @@ disable = [ # disabled because it conflicts with isort "wrong-import-order", "ungrouped-imports", - # pylint's unsubscriptable check is buggy and is not needed because - # it is a type-check, for which we already have mypy. + # Checked by mypy (and pylint is very flaky checking these) "unsubscriptable-object", - # Checked by mypy "no-member", + "no-name-in-module", + "possibly-used-before-assignment", # Checked by flake8 "f-string-without-interpolation", "line-too-long", diff --git a/tests_golden/integration/test_cookiecutter_generation/app/frequenz-app-test/pyproject.toml b/tests_golden/integration/test_cookiecutter_generation/app/frequenz-app-test/pyproject.toml index f0218f09..909dd9d1 100644 --- a/tests_golden/integration/test_cookiecutter_generation/app/frequenz-app-test/pyproject.toml +++ b/tests_golden/integration/test_cookiecutter_generation/app/frequenz-app-test/pyproject.toml @@ -136,11 +136,11 @@ disable = [ # disabled because it conflicts with isort "wrong-import-order", "ungrouped-imports", - # pylint's unsubscriptable check is buggy and is not needed because - # it is a type-check, for which we already have mypy. + # Checked by mypy (and pylint is very flaky checking these) "unsubscriptable-object", - # Checked by mypy "no-member", + "no-name-in-module", + "possibly-used-before-assignment", # Checked by flake8 "f-string-without-interpolation", "line-too-long", diff --git a/tests_golden/integration/test_cookiecutter_generation/lib/frequenz-test-python/pyproject.toml b/tests_golden/integration/test_cookiecutter_generation/lib/frequenz-test-python/pyproject.toml index 25719541..4a91ef03 100644 --- a/tests_golden/integration/test_cookiecutter_generation/lib/frequenz-test-python/pyproject.toml +++ b/tests_golden/integration/test_cookiecutter_generation/lib/frequenz-test-python/pyproject.toml @@ -133,11 +133,11 @@ disable = [ # disabled because it conflicts with isort "wrong-import-order", "ungrouped-imports", - # pylint's unsubscriptable check is buggy and is not needed because - # it is a type-check, for which we already have mypy. + # Checked by mypy (and pylint is very flaky checking these) "unsubscriptable-object", - # Checked by mypy "no-member", + "no-name-in-module", + "possibly-used-before-assignment", # Checked by flake8 "f-string-without-interpolation", "line-too-long", diff --git a/tests_golden/integration/test_cookiecutter_generation/model/frequenz-model-test/pyproject.toml b/tests_golden/integration/test_cookiecutter_generation/model/frequenz-model-test/pyproject.toml index a87851ba..7705032b 100644 --- a/tests_golden/integration/test_cookiecutter_generation/model/frequenz-model-test/pyproject.toml +++ b/tests_golden/integration/test_cookiecutter_generation/model/frequenz-model-test/pyproject.toml @@ -137,11 +137,11 @@ disable = [ # disabled because it conflicts with isort "wrong-import-order", "ungrouped-imports", - # pylint's unsubscriptable check is buggy and is not needed because - # it is a type-check, for which we already have mypy. + # Checked by mypy (and pylint is very flaky checking these) "unsubscriptable-object", - # Checked by mypy "no-member", + "no-name-in-module", + "possibly-used-before-assignment", # Checked by flake8 "f-string-without-interpolation", "line-too-long",