diff --git a/isort/api.py b/isort/api.py index f58dff9a..5db08229 100644 --- a/isort/api.py +++ b/isort/api.py @@ -66,7 +66,7 @@ class ImportKey(Enum): ALIAS = 4 -def sort_code_string( +def sort_code_string( # noqa: PLR0913 code: str, extension: Optional[str] = None, config: Config = DEFAULT_CONFIG, @@ -85,6 +85,12 @@ def sort_code_string( - **show_diff**: If `True` the changes that need to be done will be printed to stdout, if a TextIO stream is provided results will be written to it, otherwise no diff will be computed. - ****config_kwargs**: Any config modifications. + + Future modifications should consider refactoring to reduce complexity. + + * There are currently 6 function argurments vs 5 recommended. + + To revalidate these numbers, run `ruff check --select=C901,PLR091`. """ input_stream = StringIO(code) output_stream = StringIO() @@ -102,7 +108,7 @@ def sort_code_string( return output_stream.read() -def check_code_string( +def check_code_string( # noqa: PLR0913 code: str, show_diff: Union[bool, TextIO] = False, extension: Optional[str] = None, @@ -122,6 +128,12 @@ def check_code_string( - **file_path**: The disk location where the code string was pulled from. - **disregard_skip**: set to `True` if you want to ignore a skip set in config for this file. - ****config_kwargs**: Any config modifications. + + Future modifications should consider refactoring to reduce complexity. + + * There are currently 6 function argurments vs 5 recommended. + + To revalidate these numbers, run `ruff check --select=C901,PLR091`. """ config = _config(path=file_path, config=config, **config_kwargs) return check_stream( @@ -134,7 +146,7 @@ def check_code_string( ) -def sort_stream( +def sort_stream( # noqa: C901,PLR0913,PLR0912 input_stream: TextIO, output_stream: TextIO, extension: Optional[str] = None, @@ -157,6 +169,14 @@ def sort_stream( - **show_diff**: If `True` the changes that need to be done will be printed to stdout, if a TextIO stream is provided results will be written to it, otherwise no diff will be computed. - ****config_kwargs**: Any config modifications. + + Future modifications should consider refactoring to reduce complexity. + + * The McCabe cyclomatic complexity is currently 14 vs 10 recommended. + * There are currently 8 function argurments vs 5 recommended. + * There are currently 13 branches vs 12 recommended. + + To revalidate these numbers, run `ruff check --select=C901,PLR091`. """ extension = extension or (file_path and file_path.suffix.lstrip(".")) or "py" if show_diff: @@ -237,7 +257,7 @@ def sort_stream( return changed -def check_stream( +def check_stream( # noqa: PLR0913 input_stream: TextIO, show_diff: Union[bool, TextIO] = False, extension: Optional[str] = None, @@ -257,6 +277,12 @@ def check_stream( - **file_path**: The disk location where the code string was pulled from. - **disregard_skip**: set to `True` if you want to ignore a skip set in config for this file. - ****config_kwargs**: Any config modifications. + + Future modifications should consider refactoring to reduce complexity. + + * There are currently 6 function argurments vs 5 recommended. + + To revalidate these numbers, run `ruff check --select=C901,PLR091`. """ config = _config(path=file_path, config=config, **config_kwargs) @@ -304,7 +330,7 @@ def check_stream( return False -def check_file( +def check_file( # noqa: PLR0913 filename: Union[str, Path], show_diff: Union[bool, TextIO] = False, config: Config = DEFAULT_CONFIG, @@ -324,6 +350,12 @@ def check_file( - **disregard_skip**: set to `True` if you want to ignore a skip set in config for this file. - **extension**: The file extension that contains imports. Defaults to filename extension or py. - ****config_kwargs**: Any config modifications. + + Future modifications should consider refactoring to reduce complexity. + + * There are currently 6 function argurments vs 5 recommended. + + To revalidate these numbers, run `ruff check --select=C901,PLR091`. """ file_config: Config = config @@ -368,7 +400,7 @@ def _file_output_stream_context(filename: Union[str, Path], source_file: File) - # Ignore DeepSource cyclomatic complexity check for this function. It is one # the main entrypoints so sort of expected to be complex. # skipcq: PY-R1000 -def sort_file( +def sort_file( # noqa: C901,PLR0913,PLR0912,PLR0915 filename: Union[str, Path], extension: Optional[str] = None, config: Config = DEFAULT_CONFIG, @@ -395,6 +427,15 @@ def sort_file( - **output**: If a TextIO is provided, results will be written there rather than replacing the original file content. - ****config_kwargs**: Any config modifications. + + Future modifications should consider refactoring to reduce complexity. + + * The McCabe cyclomatic complexity is currently 18 vs 10 recommended. + * There are currently 9 function argurments vs 5 recommended. + * There are currently 21 branches vs 12 recommended. + * There are currently 59 statements vs 50 recommended. + + To revalidate these numbers, run `ruff check --select=C901,PLR091`. """ file_config: Config = config diff --git a/isort/core.py b/isort/core.py index bff28458..b3e93553 100644 --- a/isort/core.py +++ b/isort/core.py @@ -29,7 +29,7 @@ # Ignore DeepSource cyclomatic complexity check for this function. # skipcq: PY-R1000 -def process( +def process( # noqa: C901,PLR0912,PLR0915 input_stream: TextIO, output_stream: TextIO, extension: str = "py", @@ -51,6 +51,14 @@ def process( Returns `True` if there were changes that needed to be made (errors present) from what was provided in the input_stream, otherwise `False`. + + Future modifications should consider refactoring to reduce complexity. + + * The McCabe cyclomatic complexity is currently 91 vs 10 recommended. + * There are currently 104 branches vs 12 recommended. + * There are currently 293 statements vs 50 recommended. + + To revalidate these numbers, run `ruff check --select=C901,PLR091`. """ line_separator: str = config.line_ending add_imports: List[str] = [format_natural(addition) for addition in config.add_imports] diff --git a/isort/files.py b/isort/files.py index 28a916cb..aa6750a7 100644 --- a/isort/files.py +++ b/isort/files.py @@ -5,10 +5,18 @@ from isort.settings import Config -def find( +def find( # noqa: C901,PLR0912 paths: Iterable[str], config: Config, skipped: List[str], broken: List[str] ) -> Iterator[str]: - """Fines and provides an iterator for all Python source files defined in paths.""" + """Fines and provides an iterator for all Python source files defined in paths. + + Future modifications should consider refactoring to reduce complexity. + + * The McCabe cyclomatic complexity is currently 11 vs 10 recommended. + * There are currently 13 branches vs 12 recommended. + + To revalidate these numbers, run `ruff check --select=C901,PLR091`. + """ visited_dirs: Set[Path] = set() for path in paths: diff --git a/isort/identify.py b/isort/identify.py index da9eb822..b012a38a 100644 --- a/isort/identify.py +++ b/isort/identify.py @@ -40,13 +40,22 @@ def __str__(self) -> str: ) -def imports( +def imports( # noqa: C901,PLR0912,PLR0915 input_stream: TextIO, config: Config = DEFAULT_CONFIG, file_path: Optional[Path] = None, top_only: bool = False, ) -> Iterator[Import]: - """Parses a python file taking out and categorizing imports.""" + """Parses a python file taking out and categorizing imports. + + Future modifications should consider refactoring to reduce complexity. + + * The McCabe cyclomatic complexity is currently 33 vs 10 recommended. + * There are currently 40 branches vs 12 recommended. + * There are currently 109 statements vs 50 recommended. + + To revalidate these numbers, run `ruff check --select=C901,PLR091`. + """ in_quote = "" indexed_input = enumerate(input_stream) diff --git a/isort/main.py b/isort/main.py index 5a6447d3..f0f196c0 100644 --- a/isort/main.py +++ b/isort/main.py @@ -131,7 +131,13 @@ def _print_hard_fail( printer.error(message) -def _build_arg_parser() -> argparse.ArgumentParser: +def _build_arg_parser() -> argparse.ArgumentParser: # noqa: PLR0915 + """Future modifications should consider refactoring to reduce complexity. + + * There are currently 113 statements vs 50 recommended. + + To revalidate these numbers, run `ruff check --select=C901,PLR091`. + """ parser = argparse.ArgumentParser( description="Sort Python import definitions alphabetically " "within logical sections. Run with no arguments to see a quick " @@ -1057,7 +1063,17 @@ def identify_imports_main( print(str(identified_import)) -def main(argv: Optional[Sequence[str]] = None, stdin: Optional[TextIOWrapper] = None) -> None: +def main( # noqa: C901,PLR0912,PLR0915 + argv: Optional[Sequence[str]] = None, stdin: Optional[TextIOWrapper] = None +) -> None: + """Future modifications should consider refactoring to reduce complexity. + + * The McCabe cyclomatic complexity is currently 46 vs 10 recommended. + * There are currently 51 branches vs 12 recommended. + * There are currently 138 statements vs 50 recommended. + + To revalidate these numbers, run `ruff check --select=C901,PLR091`. + """ arguments = parse_args(argv) if arguments.get("show_version"): print(ASCII_ART) diff --git a/isort/output.py b/isort/output.py index 65a6ff7e..ad05ddc7 100644 --- a/isort/output.py +++ b/isort/output.py @@ -11,7 +11,7 @@ from .settings import DEFAULT_CONFIG, Config -def sorted_imports( +def sorted_imports( # noqa: C901,PLR0912,PLR0915 parsed: parse.ParsedContent, config: Config = DEFAULT_CONFIG, extension: str = "py", @@ -21,6 +21,13 @@ def sorted_imports( (at the index of the first import) sorted alphabetically and split between groups + Future modifications should consider refactoring to reduce complexity. + + * The McCabe cyclomatic complexity is currently 49 vs 10 recommended. + * There are currently 53 branches vs 12 recommended. + * There are currently 133 statements vs 50 recommended. + + To revalidate these numbers, run `ruff check --select=C901,PLR091`. """ if parsed.import_index == -1: return _output_as_string(parsed.lines_without_imports, parsed.line_separator) @@ -243,7 +250,7 @@ def sorted_imports( # Ignore DeepSource cyclomatic complexity check for this function. It was # already complex when this check was enabled. # skipcq: PY-R1000 -def _with_from_imports( +def _with_from_imports( # noqa: C901,PLR0913,PLR0912,PLR0915 parsed: parse.ParsedContent, config: Config, from_modules: Iterable[str], @@ -251,6 +258,15 @@ def _with_from_imports( remove_imports: List[str], import_type: str, ) -> List[str]: + """Future modifications should consider refactoring to reduce complexity. + + * The McCabe cyclomatic complexity is currently 43 vs 10 recommended. + * There are currently 6 function argurments vs 5 recommended. + * There are currently 47 branches vs 12 recommended. + * There are currently 110 statements vs 50 recommended. + + To revalidate these numbers, run `ruff check --select=C901,PLR091`. + """ output: List[str] = [] for module in from_modules: if module in remove_imports: @@ -559,7 +575,7 @@ def _with_from_imports( return output -def _with_straight_imports( +def _with_straight_imports( # noqa: C901,PLR0913,PLR0912 parsed: parse.ParsedContent, config: Config, straight_modules: Iterable[str], @@ -567,6 +583,14 @@ def _with_straight_imports( remove_imports: List[str], import_type: str, ) -> List[str]: + """Future modifications should consider refactoring to reduce complexity. + + * The McCabe cyclomatic complexity is currently 13 vs 10 recommended. + * There are currently 6 function argurments vs 5 recommended. + * There are currently 15 branches vs 12 recommended. + + To revalidate these numbers, run `ruff check --select=C901,PLR091`. + """ output: List[str] = [] as_imports = any(module in parsed.as_map["straight"] for module in straight_modules) diff --git a/isort/parse.py b/isort/parse.py index e1b20576..f5bc07cb 100644 --- a/isort/parse.py +++ b/isort/parse.py @@ -80,7 +80,7 @@ def strip_syntax(import_string: str) -> str: return import_string.replace("{ ", "{|").replace(" }", "|}") -def skip_line( +def skip_line( # noqa: C901 line: str, in_quote: str, index: int, @@ -93,6 +93,12 @@ def skip_line( (skip_line: bool, in_quote: str,) + + Future modifications should consider refactoring to reduce complexity. + + * The McCabe cyclomatic complexity is currently 12 vs 10 recommended. + + To revalidate these numbers, run `ruff check --select=C901,PLR091`. """ should_skip = bool(in_quote) if '"' in line or "'" in line: @@ -143,8 +149,19 @@ class ParsedContent(NamedTuple): trailing_commas: Set[str] -def file_contents(contents: str, config: Config = DEFAULT_CONFIG) -> ParsedContent: - """Parses a python file taking out and categorizing imports.""" +def file_contents( # noqa: C901,PLR0912,PLR0915 + contents: str, config: Config = DEFAULT_CONFIG +) -> ParsedContent: + """Parses a python file taking out and categorizing imports. + + Future modifications should consider refactoring to reduce complexity. + + * The McCabe cyclomatic complexity is currently 80 vs 10 recommended. + * There are currently 93 branches vs 12 recommended. + * There are currently 258 statements vs 50 recommended. + + To revalidate these numbers, run `ruff check --select=C901,PLR091`. + """ line_separator: str = config.line_ending or _infer_line_separator(contents) in_lines = contents.splitlines() if contents and contents[-1] in ("\n", "\r"): diff --git a/isort/settings.py b/isort/settings.py index b8281a41..57889b93 100644 --- a/isort/settings.py +++ b/isort/settings.py @@ -291,13 +291,21 @@ def __hash__(self) -> int: class Config(_Config): - def __init__( + def __init__( # noqa: C901,PLR0912,PLR0915 self, settings_file: str = "", settings_path: str = "", config: Optional[_Config] = None, **config_overrides: Any, ): + """Future modifications should consider refactoring to reduce complexity. + + * The McCabe cyclomatic complexity is currently 15 vs 10 recommended. + * There are currently 7 return statements vs 6 recommended. + * There are currently 16 branches vs 12 recommended. + + To revalidate these numbers, run `ruff check --select=C901,PLR091`. + """ self._known_patterns: Optional[List[Tuple[Pattern[str], str]]] = None self._section_comments: Optional[Tuple[str, ...]] = None self._section_comments_end: Optional[Tuple[str, ...]] = None @@ -591,8 +599,17 @@ def _check_folder_git_ls_files(self, folder: str) -> Optional[Path]: } return git_folder - def is_skipped(self, file_path: Path) -> bool: - """Returns True if the file and/or folder should be skipped based on current settings.""" + def is_skipped(self, file_path: Path) -> bool: # noqa: C901,PLR0911,PLR0912 + """Returns True if the file and/or folder should be skipped based on current settings. + + Future modifications should consider refactoring to reduce complexity. + + * The McCabe cyclomatic complexity is currently 15 vs 10 recommended. + * There are currently 7 return statements vs 6 recommended. + * There are currently 16 branches vs 12 recommended. + + To revalidate these numbers, run `ruff check --select=C901,PLR091`. + """ if self.directory and Path(self.directory) in file_path.resolve().parents: file_name = os.path.relpath(file_path.resolve(), self.directory) else: @@ -835,7 +852,17 @@ def find_all_configs(path: str) -> Trie: return trie_root -def _get_config_data(file_path: str, sections: Tuple[str, ...]) -> Dict[str, Any]: +def _get_config_data( # noqa: C901,PLR0912,PLR0915 + file_path: str, sections: Tuple[str, ...] +) -> Dict[str, Any]: + """Future modifications should consider refactoring to reduce complexity. + + * The McCabe cyclomatic complexity is currently 27 vs 10 recommended. + * There are currently 28 branches vs 12 recommended. + * There are currently 62 statements vs 50 recommended. + + To revalidate these numbers, run `ruff check --select=C901,PLR091`. + """ settings: Dict[str, Any] = {} if file_path.endswith(".toml"): diff --git a/isort/sorting.py b/isort/sorting.py index f4504f07..aa37a30b 100644 --- a/isort/sorting.py +++ b/isort/sorting.py @@ -10,7 +10,7 @@ _import_line_midline_import_re = re.compile(" import ") -def module_key( +def module_key( # noqa: PLR0913 module_name: str, config: Config, sub_imports: bool = False, @@ -18,6 +18,12 @@ def module_key( section_name: Optional[Any] = None, straight_import: Optional[bool] = False, ) -> str: + """Future modifications should consider refactoring to reduce complexity. + + * There are currently 6 function argurments vs 5 recommended. + + To revalidate these numbers, run `ruff check --select=C901,PLR091`. + """ match = re.match(r"^(\.+)\s*(.*)", module_name) if match: sep = " " if config.reverse_relative else "_" @@ -54,7 +60,14 @@ def module_key( return f"{(module_name in config.force_to_top and 'A') or 'B'}{prefix}{_length_sort_maybe}" -def section_key(line: str, config: Config) -> str: +def section_key(line: str, config: Config) -> str: # noqa: C901,PLR0912 + """Future modifications should consider refactoring to reduce complexity. + + * The McCabe cyclomatic complexity is currently 13 vs 10 recommended. + * There are currently 13 branches vs 12 recommended. + + To revalidate these numbers, run `ruff check --select=C901,PLR091`. + """ section = "B" if ( diff --git a/isort/wrap.py b/isort/wrap.py index 9eced44b..dd96a30d 100644 --- a/isort/wrap.py +++ b/isort/wrap.py @@ -7,7 +7,7 @@ from .wrap_modes import formatter_from_string, vertical_hanging_indent -def import_statement( +def import_statement( # noqa: PLR0913 import_start: str, from_imports: List[str], comments: Sequence[str] = (), @@ -16,7 +16,14 @@ def import_statement( multi_line_output: Optional[Modes] = None, explode: bool = False, ) -> str: - """Returns a multi-line wrapped form of the provided from import statement.""" + """Returns a multi-line wrapped form of the provided from import statement. + + Future modifications should consider refactoring to reduce complexity. + + * There are currently 7 function argurments vs 5 recommended. + + To revalidate these numbers, run `ruff check --select=C901,PLR091`. + """ if explode: formatter = vertical_hanging_indent line_length = 1 @@ -68,8 +75,18 @@ def import_statement( return statement -def line(content: str, line_separator: str, config: Config = DEFAULT_CONFIG) -> str: - """Returns a line wrapped to the specified line-length, if possible.""" +def line( # noqa: C901,PLR0912 + content: str, line_separator: str, config: Config = DEFAULT_CONFIG +) -> str: + """Returns a line wrapped to the specified line-length, if possible. + + Future modifications should consider refactoring to reduce complexity. + + * The McCabe cyclomatic complexity is currently 14 vs 10 recommended. + * There are currently 15 branches vs 12 recommended. + + To revalidate these numbers, run `ruff check --select=C901,PLR091`. + """ wrap_mode = config.multi_line_output if len(content) > config.line_length and wrap_mode != Modes.NOQA: # type: ignore line_without_comment = content diff --git a/isort/wrap_modes.py b/isort/wrap_modes.py index 3ae47152..a113b405 100644 --- a/isort/wrap_modes.py +++ b/isort/wrap_modes.py @@ -17,7 +17,7 @@ def formatter_from_string(name: str) -> Callable[..., str]: return _wrap_modes.get(name.upper(), grid) -def _wrap_mode_interface( +def _wrap_mode_interface( # noqa: PLR0913 statement: str, imports: List[str], white_space: str, @@ -29,7 +29,6 @@ def _wrap_mode_interface( include_trailing_comma: bool, remove_comments: bool, ) -> str: - """Defines the common interface used by all wrap mode functions""" return "" diff --git a/pyproject.toml b/pyproject.toml index 8c54ba71..b3bd9451 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -178,8 +178,7 @@ lint.select = [ "FLY", "PERF", "PIE", - "PLC", - "PLE", + "PL", "PT", "RUF", "S", @@ -190,12 +189,14 @@ lint.ignore = [ "B904", "E501", "PERF203", + "PLR5501", + "PLW", "RUF100", "UP006", "UP035", ] -lint.exclude = [ "isort/_vendored/*" ] -lint.mccabe.max-complexity = 91 # Default is 10 +lint.exclude = [ "isort/_vendored/*", "isort/deprecated/*" ] +lint.pylint.allow-magic-value-types = [ "bytes", "int", "str" ] [tool.ruff.lint.per-file-ignores] "isort/deprecated/finders.py" = [ "UP034" ] @@ -205,7 +206,8 @@ lint.mccabe.max-complexity = 91 # Default is 10 "isort/setuptools_commands.py" = [ "RUF012" ] "tests/*" = [ "RUF001", "S" ] "tests/unit/example_crlf_file.py" = [ "F401" ] -"tests/unit/test_wrap_modes.py" = [ "PIE804" ] +"tests/unit/test_main.py" = [ "PLR0915" ] +"tests/unit/test_wrap_modes.py" = [ "PIE804", "PLR0913" ] [tool.isort] profile = "hug"