Skip to content
Closed
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
6 changes: 0 additions & 6 deletions pylint/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,11 @@
HAS_ISORT_5,
IsortDriver,
_check_csv,
_format_option_value,
_splitstrip,
_unquote,
decoding_stream,
diff_string,
format_section,
get_module_and_frameid,
get_rst_section,
get_rst_title,
normalize_text,
register_plugins,
Expand All @@ -33,15 +30,12 @@
"HAS_ISORT_5",
"IsortDriver",
"_check_csv",
"_format_option_value",
"_splitstrip",
"_unquote",
"decoding_stream",
"diff_string",
"FileState",
"format_section",
"get_module_and_frameid",
"get_rst_section",
"get_rst_title",
"normalize_text",
"register_plugins",
Expand Down
3 changes: 1 addition & 2 deletions pylint/utils/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from typing import TYPE_CHECKING, Any, TextIO

from pylint.constants import MAIN_CHECKER_NAME
from pylint.utils.utils import get_rst_section, get_rst_title
from pylint.utils.utils import get_rst_title

if TYPE_CHECKING:
from pylint.lint.pylinter import PyLinter
Expand Down Expand Up @@ -53,7 +53,6 @@ def _get_global_options_documentation(linter: PyLinter) -> str:
title = f"{section.capitalize()} options"
result += get_rst_title(title, "~")
assert isinstance(options, list)
result += f"{get_rst_section(None, options)}\n"
return result


Expand Down
105 changes: 1 addition & 104 deletions pylint/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,16 @@
import argparse
import codecs
import os
import re
import sys
import textwrap
import tokenize
import warnings
from collections.abc import Sequence
from io import BufferedReader, BytesIO
from typing import TYPE_CHECKING, Any, List, Pattern, TextIO, Tuple, TypeVar, Union
from typing import TYPE_CHECKING, List, Pattern, Tuple, TypeVar, Union

from astroid import Module, modutils, nodes

from pylint.constants import PY_EXTS
from pylint.typing import OptionDict

if sys.version_info >= (3, 8):
from typing import Literal
Expand Down Expand Up @@ -128,31 +125,6 @@ def get_rst_title(title: str, character: str) -> str:
return f"{title}\n{character * len(title)}\n"


def get_rst_section(
section: str | None,
options: list[tuple[str, OptionDict, Any]],
doc: str | None = None,
) -> str:
"""Format an option's section using as a ReStructuredText formatted output."""
result = ""
if section:
result += get_rst_title(section, "'")
if doc:
formatted_doc = normalize_text(doc)
result += f"{formatted_doc}\n\n"
for optname, optdict, value in options:
help_opt = optdict.get("help")
result += f":{optname}:\n"
if help_opt:
assert isinstance(help_opt, str)
formatted_help = normalize_text(help_opt, indent=" ")
result += f"{formatted_help}\n"
if value and optname != "py-version":
value = str(_format_option_value(optdict, value))
result += f"\n Default: ``{value.replace('`` ', '```` ``')}``\n"
return result


def decoding_stream(
stream: BufferedReader | BytesIO,
encoding: str,
Expand Down Expand Up @@ -255,81 +227,6 @@ def _comment(string: str) -> str:
return "# " + f"{sep}# ".join(lines)


def _format_option_value(optdict: OptionDict, value: Any) -> str:
"""Return the user input's value from a 'compiled' value.

TODO: 3.0: Remove deprecated function
"""
if optdict.get("type", None) == "py_version":
value = ".".join(str(item) for item in value)
elif isinstance(value, (list, tuple)):
value = ",".join(_format_option_value(optdict, item) for item in value)
elif isinstance(value, dict):
value = ",".join(f"{k}:{v}" for k, v in value.items())
elif hasattr(value, "match"): # optdict.get('type') == 'regexp'
# compiled regexp
value = value.pattern
elif optdict.get("type") == "yn":
value = "yes" if value else "no"
elif isinstance(value, str) and value.isspace():
value = f"'{value}'"
return str(value)


def format_section(
stream: TextIO,
section: str,
options: list[tuple[str, OptionDict, Any]],
doc: str | None = None,
) -> None:
"""Format an option's section using the INI format."""
warnings.warn(
"format_section has been deprecated. It will be removed in pylint 3.0.",
DeprecationWarning,
stacklevel=2,
)
if doc:
print(_comment(doc), file=stream)
print(f"[{section}]", file=stream)
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=DeprecationWarning)
_ini_format(stream, options)


def _ini_format(stream: TextIO, options: list[tuple[str, OptionDict, Any]]) -> None:
"""Format options using the INI format."""
warnings.warn(
"_ini_format has been deprecated. It will be removed in pylint 3.0.",
DeprecationWarning,
stacklevel=2,
)
for optname, optdict, value in options:
# Skip deprecated option
if "kwargs" in optdict:
assert isinstance(optdict["kwargs"], dict)
if "new_names" in optdict["kwargs"]:
continue
value = _format_option_value(optdict, value)
help_opt = optdict.get("help")
if help_opt:
assert isinstance(help_opt, str)
help_opt = normalize_text(help_opt, indent="# ")
print(file=stream)
print(help_opt, file=stream)
else:
print(file=stream)
if value in {"None", "False"}:
print(f"#{optname}=", file=stream)
else:
value = str(value).strip()
if re.match(r"^([\w-]+,)+[\w-]+$", str(value)):
separator = "\n " + " " * len(optname)
value = separator.join(x + "," for x in str(value).split(","))
# remove trailing ',' from last element of the list
value = value[:-1]
print(f"{optname}={value}", file=stream)


class IsortDriver:
"""A wrapper around isort API that changed between versions 4 and 5."""

Expand Down