Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade pylint and add ignores for new check #748

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ Added
- Display exit code in parentheses after error message.
- Do not reformat renamed files.
- The ``--preview`` configuration flag is now supported in the configuration files for
Darker and Black
Darker and Black.
- Prevent Pylint from updating beyond version 3.2.7 due to dropped Python 3.8 support.
- The ``--formatter=black`` option (the default) has been added in preparation for
future formatters.
- ``--formatter=none`` now skips running Black. This is useful when you only want to run
Expand All @@ -19,6 +20,8 @@ Added
Black support.
- pyupgrade_ is now supported as a formatter plugin. Note that changes from pyupgrade
are applied on a per-file basis, not only for modified lines as with Black_ and Ruff_.
- For linting Darker itself, upgrade to Pylint 3.3.0 or later, and add ignores for the
``too-many-positional-arguments`` message.

Removed
-------
Expand Down
1 change: 1 addition & 0 deletions constraints-oldest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ flake8-comprehensions==3.7.0
flynt==0.76
mypy==0.990
Pygments==2.4.0
pylint==3.3.0
pytest==6.2.0
pytest-kwparametrize==0.0.3
regex==2021.4.4
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ test =
pathspec # to test `gen_python_files` in `test_black_diff.py`
pydocstyle
pygments
pylint<=3.2.7 # pylint 3.3.0 dropped Python 3.8 support
pylint>=3.3.0
pylint-per-file-ignores
pytest>=6.2.0
pytest-kwparametrize>=0.0.3
Expand Down
9 changes: 5 additions & 4 deletions src/darker/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
ProcessedDocument = Tuple[Path, TextDocument, TextDocument]


def format_edited_parts( # noqa: PLR0913 # pylint: disable=too-many-arguments
def format_edited_parts( # noqa: PLR0913
root: Path,
changed_files: Collection[Path],
exclude: Exclusions,
Expand All @@ -67,6 +67,7 @@
report_unmodified: bool,
workers: int = 1,
) -> Generator[ProcessedDocument, None, None]:
# pylint: disable=too-many-arguments,too-many-positional-arguments

Check failure on line 70 in src/darker/__main__.py

View workflow job for this annotation

GitHub Actions / Pylint

src/darker/__main__.py#L70

Unknown option value for 'disable', expected a valid pylint message and got 'too-many-positional-arguments' (unknown-option-value, W0012)
"""Black (and optional isort and flynt) formatting modified chunks in a set of files

Files inside given directories and excluded by Black's configuration are not
Expand Down Expand Up @@ -121,7 +122,7 @@
revrange: RevisionRange,
formatter: BaseFormatter,
) -> ProcessedDocument:
# pylint: disable=too-many-arguments
# pylint: disable=too-many-arguments,too-many-positional-arguments

Check failure on line 125 in src/darker/__main__.py

View workflow job for this annotation

GitHub Actions / Pylint

src/darker/__main__.py#L125

Unknown option value for 'disable', expected a valid pylint message and got 'too-many-positional-arguments' (unknown-option-value, W0012)
"""Black, isort and/or flynt formatting for modified chunks in a single file

:param root: Root directory for the relative path
Expand Down Expand Up @@ -179,7 +180,7 @@
has_isort_changes: bool,
formatter: BaseFormatter,
) -> TextDocument:
# pylint: disable=too-many-arguments
# pylint: disable=too-many-arguments,too-many-positional-arguments,too-many-locals

Check failure on line 183 in src/darker/__main__.py

View workflow job for this annotation

GitHub Actions / Pylint

src/darker/__main__.py#L183

Unknown option value for 'disable', expected a valid pylint message and got 'too-many-positional-arguments' (unknown-option-value, W0012)
"""In a Python file, reformat chunks with edits since the last commit using Black

:param root: The common root of all files to reformat
Expand Down Expand Up @@ -306,7 +307,7 @@


def _drop_changes_on_unedited_lines(
# pylint: disable=too-many-arguments
# pylint: disable=too-many-arguments,too-many-positional-arguments

Check failure on line 310 in src/darker/__main__.py

View workflow job for this annotation

GitHub Actions / Pylint

src/darker/__main__.py#L310

Unknown option value for 'disable', expected a valid pylint message and got 'too-many-positional-arguments' (unknown-option-value, W0012)
new_chunks: List[DiffChunk],
abspath_in_rev2: Path,
relpath_in_repo: Path,
Expand Down
3 changes: 2 additions & 1 deletion src/darker/import_sorting.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,15 @@
settings_path: str


def apply_isort( # pylint: disable=too-many-arguments
def apply_isort( # noqa: PLR0913
content: TextDocument,
src: Path,
exclude: Collection[str],
edited_linenums_differ: EditedLinenumsDiffer,
config: Optional[str] = None,
line_length: Optional[int] = None,
) -> TextDocument:
# pylint: disable=too-many-arguments,too-many-positional-arguments

Check failure on line 62 in src/darker/import_sorting.py

View workflow job for this annotation

GitHub Actions / Pylint

src/darker/import_sorting.py#L62

Unknown option value for 'disable', expected a valid pylint message and got 'too-many-positional-arguments' (unknown-option-value, W0012)
"""Run isort on the given Python source file content

:param content: The contents of the Python source code file to sort imports in
Expand Down
12 changes: 10 additions & 2 deletions src/darker/tests/helpers.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
"""Helper functions for unit tests"""

from __future__ import annotations

import sys
from contextlib import contextmanager
from types import ModuleType
from typing import Generator, Optional
from typing import TYPE_CHECKING, Generator, Optional
from unittest.mock import patch

from darkgraylib.testtools.git_repo_plugin import GitRepoFixture

if TYPE_CHECKING:
import pytest
from _pytest.fixtures import SubRequest


@contextmanager
def _package_present(
Expand Down Expand Up @@ -56,7 +62,9 @@ def flynt_present(present: bool) -> Generator[None, None, None]:


@contextmanager
def unix_and_windows_newline_repos(request, tmp_path_factory):
def unix_and_windows_newline_repos(
request: SubRequest, tmp_path_factory: pytest.TempPathFactory
) -> Generator[dict[str, GitRepoFixture], None, None]:
"""Create temporary repositories for Unix and windows newlines separately."""
with GitRepoFixture.context(
request, tmp_path_factory
Expand Down
2 changes: 1 addition & 1 deletion src/darker/tests/test_command_line.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Unit tests for `darker.command_line` and `darker.__main__`."""

# pylint: disable=too-many-arguments,too-many-locals
# pylint: disable=too-many-arguments,too-many-positional-arguments,too-many-locals

Check failure on line 3 in src/darker/tests/test_command_line.py

View workflow job for this annotation

GitHub Actions / Pylint

src/darker/tests/test_command_line.py#L3

Unknown option value for 'disable', expected a valid pylint message and got 'too-many-positional-arguments' (unknown-option-value, W0012)
# pylint: disable=no-member,redefined-outer-name,unused-argument,use-dict-literal

from __future__ import annotations
Expand Down
3 changes: 2 additions & 1 deletion src/darker/tests/test_config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Tests for `darker.config`"""

# pylint: disable=unused-argument,too-many-arguments,use-dict-literal
# pylint: disable=unused-argument,too-many-arguments,too-many-positional-arguments

Check failure on line 3 in src/darker/tests/test_config.py

View workflow job for this annotation

GitHub Actions / Pylint

src/darker/tests/test_config.py#L3

Unknown option value for 'disable', expected a valid pylint message and got 'too-many-positional-arguments' (unknown-option-value, W0012)
# pylint: disable=use-dict-literal

from argparse import Namespace
from pathlib import Path
Expand Down
5 changes: 3 additions & 2 deletions src/darker/tests/test_formatters_black.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Unit tests for `darker.black_formatter`"""

# pylint: disable=too-many-arguments,use-dict-literal
# pylint: disable=too-many-arguments,too-many-positional-arguments,use-dict-literal

Check failure on line 3 in src/darker/tests/test_formatters_black.py

View workflow job for this annotation

GitHub Actions / Pylint

src/darker/tests/test_formatters_black.py#L3

Unknown option value for 'disable', expected a valid pylint message and got 'too-many-positional-arguments' (unknown-option-value, W0012)

import re
import sys
Expand Down Expand Up @@ -198,9 +198,10 @@
extend_exclude=None,
force_exclude=None,
)
def test_filter_python_files( # pylint: disable=too-many-arguments
def test_filter_python_files(
tmp_path, monkeypatch, exclude, extend_exclude, force_exclude, expect
):
# pylint: disable=too-many-arguments,too-many-positional-arguments

Check failure on line 204 in src/darker/tests/test_formatters_black.py

View workflow job for this annotation

GitHub Actions / Pylint

src/darker/tests/test_formatters_black.py#L204

Unknown option value for 'disable', expected a valid pylint message and got 'too-many-positional-arguments' (unknown-option-value, W0012)
"""``filter_python_files()`` skips excluded files correctly"""
monkeypatch.chdir(tmp_path)
names = {
Expand Down
3 changes: 2 additions & 1 deletion src/darker/tests/test_fstring.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Tests for :mod:`darker.fstring`"""

# pylint: disable=unused-argument,protected-access,too-many-arguments
# pylint: disable=protected-access
# pylint: disable=too-many-arguments,too-many-positional-arguments,unused-argument

Check failure on line 4 in src/darker/tests/test_fstring.py

View workflow job for this annotation

GitHub Actions / Pylint

src/darker/tests/test_fstring.py#L4

Unknown option value for 'disable', expected a valid pylint message and got 'too-many-positional-arguments' (unknown-option-value, W0012)

from importlib import reload
from pathlib import Path
Expand Down
10 changes: 7 additions & 3 deletions src/darker/tests/test_git.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
"""Unit tests for :mod:`darker.git`"""

# pylint: disable=no-member,protected-access,redefined-outer-name,too-many-arguments
# pylint: disable=too-many-lines,use-dict-literal
# pylint: disable=no-member,protected-access,redefined-outer-name,use-dict-literal
# pylint: disable=too-many-arguments,too-many-positional-arguments,too-many-lines

Check failure on line 4 in src/darker/tests/test_git.py

View workflow job for this annotation

GitHub Actions / Pylint

src/darker/tests/test_git.py#L4

Unknown option value for 'disable', expected a valid pylint message and got 'too-many-positional-arguments' (unknown-option-value, W0012)

import os
from pathlib import Path
from subprocess import DEVNULL, check_call # nosec
from textwrap import dedent # nosec
from types import SimpleNamespace
from typing import Generator
from unittest.mock import ANY, patch

import pytest
from _pytest.fixtures import SubRequest

from darker import git
from darkgraylib.git import WORKTREE, RevisionRange
Expand Down Expand Up @@ -321,7 +323,9 @@


@pytest.fixture(scope="module")
def git_get_modified_python_files_revision_range_repo(request, tmp_path_factory):
def git_get_modified_python_files_revision_range_repo(
request: SubRequest, tmp_path_factory: pytest.TempPathFactory
) -> Generator[GitRepoFixture, None, None]:
"""Fixture for a Git repository with multiple commits and branches."""
yield from branched_repo(request, tmp_path_factory)

Expand Down
4 changes: 2 additions & 2 deletions src/darker/tests/test_import_sorting.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Tests for :mod:`darker.import_sorting`"""

# pylint: disable=no-member,protected-access,redefined-outer-name,too-many-arguments
# pylint: disable=unused-argument,use-dict-literal
# pylint: disable=no-member,protected-access,redefined-outer-name,use-dict-literal
# pylint: disable=too-many-arguments,too-many-positional-arguments,unused-argument

Check failure on line 4 in src/darker/tests/test_import_sorting.py

View workflow job for this annotation

GitHub Actions / Pylint

src/darker/tests/test_import_sorting.py#L4

Unknown option value for 'disable', expected a valid pylint message and got 'too-many-positional-arguments' (unknown-option-value, W0012)

from importlib import reload
from pathlib import Path
Expand Down
6 changes: 3 additions & 3 deletions src/darker/tests/test_main.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""Unit tests for :mod:`darker.__main__`"""

# pylint: disable=too-many-locals,use-implicit-booleaness-not-comparison,unused-argument
# pylint: disable=no-member,protected-access,redefined-outer-name,too-many-arguments
# pylint: disable=use-dict-literal
# pylint: disable=no-member,too-many-locals,use-implicit-booleaness-not-comparison
# pylint: disable=protected-access,redefined-outer-name,use-dict-literal,
# pylint: disable=too-many-arguments,too-many-positional-arguments,unused-argument

Check failure on line 5 in src/darker/tests/test_main.py

View workflow job for this annotation

GitHub Actions / Pylint

src/darker/tests/test_main.py#L5

Unknown option value for 'disable', expected a valid pylint message and got 'too-many-positional-arguments' (unknown-option-value, W0012)

import random
import re
Expand Down
5 changes: 3 additions & 2 deletions src/darker/tests/test_main_format_edited_parts.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""Tests for the `darker.__main__.format_edited_parts` function."""

# pylint: disable=no-member,redefined-outer-name,too-many-arguments,use-dict-literal
# pylint: disable=use-implicit-booleaness-not-comparison
# pylint: disable=no-member,redefined-outer-name
# pylint: disable=too-many-arguments,too-many-positional-arguments

Check failure on line 4 in src/darker/tests/test_main_format_edited_parts.py

View workflow job for this annotation

GitHub Actions / Pylint

src/darker/tests/test_main_format_edited_parts.py#L4

Unknown option value for 'disable', expected a valid pylint message and got 'too-many-positional-arguments' (unknown-option-value, W0012)
# pylint: disable=use-dict-literal,use-implicit-booleaness-not-comparison

import logging
import re
Expand Down
3 changes: 2 additions & 1 deletion src/darker/tests/test_main_reformat_and_flynt_single_file.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Unit tests for `darker.__main__._reformat_and_flynt_single_file`."""

# pylint: disable=no-member,redefined-outer-name,too-many-arguments,use-dict-literal
# pylint: disable=no-member,redefined-outer-name
# pylint: disable=too-many-arguments,too-many-positional-arguments,use-dict-literal

Check failure on line 4 in src/darker/tests/test_main_reformat_and_flynt_single_file.py

View workflow job for this annotation

GitHub Actions / Pylint

src/darker/tests/test_main_reformat_and_flynt_single_file.py#L4

Unknown option value for 'disable', expected a valid pylint message and got 'too-many-positional-arguments' (unknown-option-value, W0012)

from pathlib import Path
from textwrap import dedent
Expand Down
3 changes: 2 additions & 1 deletion src/darker/tests/test_main_revision.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Unit tests for the ``--revision`` argument in `darker.main`"""

# pylint: disable=no-member,redefined-outer-name,too-many-arguments,use-dict-literal
# pylint: disable=no-member,redefined-outer-name
# pylint: disable=too-many-arguments,too-many-positional-arguments,use-dict-literal

Check failure on line 4 in src/darker/tests/test_main_revision.py

View workflow job for this annotation

GitHub Actions / Pylint

src/darker/tests/test_main_revision.py#L4

Unknown option value for 'disable', expected a valid pylint message and got 'too-many-positional-arguments' (unknown-option-value, W0012)

import pytest

Expand Down
3 changes: 2 additions & 1 deletion src/darker/tests/test_main_stdin_filename.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Tests for `darker.__main__.main` and the ``--stdin-filename`` option"""

# pylint: disable=no-member,redefined-outer-name,too-many-arguments,use-dict-literal
# pylint: disable=no-member,redefined-outer-name
# pylint: disable=too-many-arguments,too-many-positional-arguments,use-dict-literal

Check failure on line 4 in src/darker/tests/test_main_stdin_filename.py

View workflow job for this annotation

GitHub Actions / Pylint

src/darker/tests/test_main_stdin_filename.py#L4

Unknown option value for 'disable', expected a valid pylint message and got 'too-many-positional-arguments' (unknown-option-value, W0012)

from __future__ import annotations

Expand Down
Loading