Skip to content

Commit

Permalink
Disable more pylint checks that are also checked by mypy
Browse files Browse the repository at this point in the history
pylint has some false positive for these checks, so better to just rely
on mypy for them.

Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
  • Loading branch information
llucax committed Nov 20, 2024
1 parent 01ee0dd commit 2b7df79
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 20 deletions.
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
39 changes: 39 additions & 0 deletions cookiecutter/migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions cookiecutter/{{cookiecutter.github_repo_name}}/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 2b7df79

Please sign in to comment.