Skip to content

Commit b1932a1

Browse files
committed
Document areas of code complexity
1 parent 3305894 commit b1932a1

File tree

12 files changed

+217
-36
lines changed

12 files changed

+217
-36
lines changed

isort/api.py

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class ImportKey(Enum):
6666
ALIAS = 4
6767

6868

69-
def sort_code_string(
69+
def sort_code_string( # noqa: PLR0913
7070
code: str,
7171
extension: Optional[str] = None,
7272
config: Config = DEFAULT_CONFIG,
@@ -85,6 +85,12 @@ def sort_code_string(
8585
- **show_diff**: If `True` the changes that need to be done will be printed to stdout, if a
8686
TextIO stream is provided results will be written to it, otherwise no diff will be computed.
8787
- ****config_kwargs**: Any config modifications.
88+
89+
Future modifications should consider refactoring to reduce complexity.
90+
91+
* There are currently 6 function argurments vs 5 recommended.
92+
93+
To revalidate these numbers, run `ruff check --select=C901,PLR091`.
8894
"""
8995
input_stream = StringIO(code)
9096
output_stream = StringIO()
@@ -102,7 +108,7 @@ def sort_code_string(
102108
return output_stream.read()
103109

104110

105-
def check_code_string(
111+
def check_code_string( # noqa: PLR0913
106112
code: str,
107113
show_diff: Union[bool, TextIO] = False,
108114
extension: Optional[str] = None,
@@ -122,6 +128,12 @@ def check_code_string(
122128
- **file_path**: The disk location where the code string was pulled from.
123129
- **disregard_skip**: set to `True` if you want to ignore a skip set in config for this file.
124130
- ****config_kwargs**: Any config modifications.
131+
132+
Future modifications should consider refactoring to reduce complexity.
133+
134+
* There are currently 6 function argurments vs 5 recommended.
135+
136+
To revalidate these numbers, run `ruff check --select=C901,PLR091`.
125137
"""
126138
config = _config(path=file_path, config=config, **config_kwargs)
127139
return check_stream(
@@ -134,7 +146,7 @@ def check_code_string(
134146
)
135147

136148

137-
def sort_stream(
149+
def sort_stream( # noqa: C901,PLR0913,PLR0912
138150
input_stream: TextIO,
139151
output_stream: TextIO,
140152
extension: Optional[str] = None,
@@ -157,6 +169,14 @@ def sort_stream(
157169
- **show_diff**: If `True` the changes that need to be done will be printed to stdout, if a
158170
TextIO stream is provided results will be written to it, otherwise no diff will be computed.
159171
- ****config_kwargs**: Any config modifications.
172+
173+
Future modifications should consider refactoring to reduce complexity.
174+
175+
* The McCabe cyclomatic complexity is currently 14 vs 10 recommended.
176+
* There are currently 8 function argurments vs 5 recommended.
177+
* There are currently 13 branches vs 12 recommended.
178+
179+
To revalidate these numbers, run `ruff check --select=C901,PLR091`.
160180
"""
161181
extension = extension or (file_path and file_path.suffix.lstrip(".")) or "py"
162182
if show_diff:
@@ -237,7 +257,7 @@ def sort_stream(
237257
return changed
238258

239259

240-
def check_stream(
260+
def check_stream( # noqa: PLR0913
241261
input_stream: TextIO,
242262
show_diff: Union[bool, TextIO] = False,
243263
extension: Optional[str] = None,
@@ -257,6 +277,12 @@ def check_stream(
257277
- **file_path**: The disk location where the code string was pulled from.
258278
- **disregard_skip**: set to `True` if you want to ignore a skip set in config for this file.
259279
- ****config_kwargs**: Any config modifications.
280+
281+
Future modifications should consider refactoring to reduce complexity.
282+
283+
* There are currently 6 function argurments vs 5 recommended.
284+
285+
To revalidate these numbers, run `ruff check --select=C901,PLR091`.
260286
"""
261287
config = _config(path=file_path, config=config, **config_kwargs)
262288

@@ -304,7 +330,7 @@ def check_stream(
304330
return False
305331

306332

307-
def check_file(
333+
def check_file( # noqa: PLR0913
308334
filename: Union[str, Path],
309335
show_diff: Union[bool, TextIO] = False,
310336
config: Config = DEFAULT_CONFIG,
@@ -324,6 +350,12 @@ def check_file(
324350
- **disregard_skip**: set to `True` if you want to ignore a skip set in config for this file.
325351
- **extension**: The file extension that contains imports. Defaults to filename extension or py.
326352
- ****config_kwargs**: Any config modifications.
353+
354+
Future modifications should consider refactoring to reduce complexity.
355+
356+
* There are currently 6 function argurments vs 5 recommended.
357+
358+
To revalidate these numbers, run `ruff check --select=C901,PLR091`.
327359
"""
328360
file_config: Config = config
329361

@@ -368,7 +400,7 @@ def _file_output_stream_context(filename: Union[str, Path], source_file: File) -
368400
# Ignore DeepSource cyclomatic complexity check for this function. It is one
369401
# the main entrypoints so sort of expected to be complex.
370402
# skipcq: PY-R1000
371-
def sort_file(
403+
def sort_file( # noqa: C901,PLR0913,PLR0912,PLR0915
372404
filename: Union[str, Path],
373405
extension: Optional[str] = None,
374406
config: Config = DEFAULT_CONFIG,
@@ -395,6 +427,15 @@ def sort_file(
395427
- **output**: If a TextIO is provided, results will be written there rather than replacing
396428
the original file content.
397429
- ****config_kwargs**: Any config modifications.
430+
431+
Future modifications should consider refactoring to reduce complexity.
432+
433+
* The McCabe cyclomatic complexity is currently 18 vs 10 recommended.
434+
* There are currently 9 function argurments vs 5 recommended.
435+
* There are currently 21 branches vs 12 recommended.
436+
* There are currently 59 statements vs 50 recommended.
437+
438+
To revalidate these numbers, run `ruff check --select=C901,PLR091`.
398439
"""
399440
file_config: Config = config
400441

isort/core.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
# Ignore DeepSource cyclomatic complexity check for this function.
3131
# skipcq: PY-R1000
32-
def process(
32+
def process( # noqa: C901,PLR0912,PLR0915
3333
input_stream: TextIO,
3434
output_stream: TextIO,
3535
extension: str = "py",
@@ -51,6 +51,14 @@ def process(
5151
5252
Returns `True` if there were changes that needed to be made (errors present) from what
5353
was provided in the input_stream, otherwise `False`.
54+
55+
Future modifications should consider refactoring to reduce complexity.
56+
57+
* The McCabe cyclomatic complexity is currently 91 vs 10 recommended.
58+
* There are currently 104 branches vs 12 recommended.
59+
* There are currently 293 statements vs 50 recommended.
60+
61+
To revalidate these numbers, run `ruff check --select=C901,PLR091`.
5462
"""
5563
line_separator: str = config.line_ending
5664
add_imports: List[str] = [format_natural(addition) for addition in config.add_imports]

isort/files.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,18 @@
55
from isort.settings import Config
66

77

8-
def find(
8+
def find( # noqa: C901,PLR0912
99
paths: Iterable[str], config: Config, skipped: List[str], broken: List[str]
1010
) -> Iterator[str]:
11-
"""Fines and provides an iterator for all Python source files defined in paths."""
11+
"""Fines and provides an iterator for all Python source files defined in paths.
12+
13+
Future modifications should consider refactoring to reduce complexity.
14+
15+
* The McCabe cyclomatic complexity is currently 11 vs 10 recommended.
16+
* There are currently 13 branches vs 12 recommended.
17+
18+
To revalidate these numbers, run `ruff check --select=C901,PLR091`.
19+
"""
1220
visited_dirs: Set[Path] = set()
1321

1422
for path in paths:

isort/identify.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,22 @@ def __str__(self) -> str:
4040
)
4141

4242

43-
def imports(
43+
def imports( # noqa: C901,PLR0912,PLR0915
4444
input_stream: TextIO,
4545
config: Config = DEFAULT_CONFIG,
4646
file_path: Optional[Path] = None,
4747
top_only: bool = False,
4848
) -> Iterator[Import]:
49-
"""Parses a python file taking out and categorizing imports."""
49+
"""Parses a python file taking out and categorizing imports.
50+
51+
Future modifications should consider refactoring to reduce complexity.
52+
53+
* The McCabe cyclomatic complexity is currently 33 vs 10 recommended.
54+
* There are currently 40 branches vs 12 recommended.
55+
* There are currently 109 statements vs 50 recommended.
56+
57+
To revalidate these numbers, run `ruff check --select=C901,PLR091`.
58+
"""
5059
in_quote = ""
5160

5261
indexed_input = enumerate(input_stream)

isort/main.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,13 @@ def _print_hard_fail(
131131
printer.error(message)
132132

133133

134-
def _build_arg_parser() -> argparse.ArgumentParser:
134+
def _build_arg_parser() -> argparse.ArgumentParser: # noqa: PLR0915
135+
"""Future modifications should consider refactoring to reduce complexity.
136+
137+
* There are currently 113 statements vs 50 recommended.
138+
139+
To revalidate these numbers, run `ruff check --select=C901,PLR091`.
140+
"""
135141
parser = argparse.ArgumentParser(
136142
description="Sort Python import definitions alphabetically "
137143
"within logical sections. Run with no arguments to see a quick "
@@ -1057,7 +1063,17 @@ def identify_imports_main(
10571063
print(str(identified_import))
10581064

10591065

1060-
def main(argv: Optional[Sequence[str]] = None, stdin: Optional[TextIOWrapper] = None) -> None:
1066+
def main( # noqa: C901,PLR0912,PLR0915
1067+
argv: Optional[Sequence[str]] = None, stdin: Optional[TextIOWrapper] = None
1068+
) -> None:
1069+
"""Future modifications should consider refactoring to reduce complexity.
1070+
1071+
* The McCabe cyclomatic complexity is currently 46 vs 10 recommended.
1072+
* There are currently 51 branches vs 12 recommended.
1073+
* There are currently 138 statements vs 50 recommended.
1074+
1075+
To revalidate these numbers, run `ruff check --select=C901,PLR091`.
1076+
"""
10611077
arguments = parse_args(argv)
10621078
if arguments.get("show_version"):
10631079
print(ASCII_ART)

isort/output.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from .settings import DEFAULT_CONFIG, Config
1212

1313

14-
def sorted_imports(
14+
def sorted_imports( # noqa: C901,PLR0912,PLR0915
1515
parsed: parse.ParsedContent,
1616
config: Config = DEFAULT_CONFIG,
1717
extension: str = "py",
@@ -21,6 +21,13 @@ def sorted_imports(
2121
2222
(at the index of the first import) sorted alphabetically and split between groups
2323
24+
Future modifications should consider refactoring to reduce complexity.
25+
26+
* The McCabe cyclomatic complexity is currently 49 vs 10 recommended.
27+
* There are currently 53 branches vs 12 recommended.
28+
* There are currently 133 statements vs 50 recommended.
29+
30+
To revalidate these numbers, run `ruff check --select=C901,PLR091`.
2431
"""
2532
if parsed.import_index == -1:
2633
return _output_as_string(parsed.lines_without_imports, parsed.line_separator)
@@ -243,14 +250,23 @@ def sorted_imports(
243250
# Ignore DeepSource cyclomatic complexity check for this function. It was
244251
# already complex when this check was enabled.
245252
# skipcq: PY-R1000
246-
def _with_from_imports(
253+
def _with_from_imports( # noqa: C901,PLR0913,PLR0912,PLR0915
247254
parsed: parse.ParsedContent,
248255
config: Config,
249256
from_modules: Iterable[str],
250257
section: str,
251258
remove_imports: List[str],
252259
import_type: str,
253260
) -> List[str]:
261+
"""Future modifications should consider refactoring to reduce complexity.
262+
263+
* The McCabe cyclomatic complexity is currently 43 vs 10 recommended.
264+
* There are currently 6 function argurments vs 5 recommended.
265+
* There are currently 47 branches vs 12 recommended.
266+
* There are currently 110 statements vs 50 recommended.
267+
268+
To revalidate these numbers, run `ruff check --select=C901,PLR091`.
269+
"""
254270
output: List[str] = []
255271
for module in from_modules:
256272
if module in remove_imports:
@@ -559,14 +575,22 @@ def _with_from_imports(
559575
return output
560576

561577

562-
def _with_straight_imports(
578+
def _with_straight_imports( # noqa: C901,PLR0913,PLR0912
563579
parsed: parse.ParsedContent,
564580
config: Config,
565581
straight_modules: Iterable[str],
566582
section: str,
567583
remove_imports: List[str],
568584
import_type: str,
569585
) -> List[str]:
586+
"""Future modifications should consider refactoring to reduce complexity.
587+
588+
* The McCabe cyclomatic complexity is currently 13 vs 10 recommended.
589+
* There are currently 6 function argurments vs 5 recommended.
590+
* There are currently 15 branches vs 12 recommended.
591+
592+
To revalidate these numbers, run `ruff check --select=C901,PLR091`.
593+
"""
570594
output: List[str] = []
571595

572596
as_imports = any(module in parsed.as_map["straight"] for module in straight_modules)

isort/parse.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def strip_syntax(import_string: str) -> str:
8080
return import_string.replace("{ ", "{|").replace(" }", "|}")
8181

8282

83-
def skip_line(
83+
def skip_line( # noqa: C901
8484
line: str,
8585
in_quote: str,
8686
index: int,
@@ -93,6 +93,12 @@ def skip_line(
9393
9494
(skip_line: bool,
9595
in_quote: str,)
96+
97+
Future modifications should consider refactoring to reduce complexity.
98+
99+
* The McCabe cyclomatic complexity is currently 12 vs 10 recommended.
100+
101+
To revalidate these numbers, run `ruff check --select=C901,PLR091`.
96102
"""
97103
should_skip = bool(in_quote)
98104
if '"' in line or "'" in line:
@@ -143,8 +149,19 @@ class ParsedContent(NamedTuple):
143149
trailing_commas: Set[str]
144150

145151

146-
def file_contents(contents: str, config: Config = DEFAULT_CONFIG) -> ParsedContent:
147-
"""Parses a python file taking out and categorizing imports."""
152+
def file_contents( # noqa: C901,PLR0912,PLR0915
153+
contents: str, config: Config = DEFAULT_CONFIG
154+
) -> ParsedContent:
155+
"""Parses a python file taking out and categorizing imports.
156+
157+
Future modifications should consider refactoring to reduce complexity.
158+
159+
* The McCabe cyclomatic complexity is currently 80 vs 10 recommended.
160+
* There are currently 93 branches vs 12 recommended.
161+
* There are currently 258 statements vs 50 recommended.
162+
163+
To revalidate these numbers, run `ruff check --select=C901,PLR091`.
164+
"""
148165
line_separator: str = config.line_ending or _infer_line_separator(contents)
149166
in_lines = contents.splitlines()
150167
if contents and contents[-1] in ("\n", "\r"):

0 commit comments

Comments
 (0)