Skip to content

Commit ade3306

Browse files
committed
Document areas of code complexity
1 parent 1157b58 commit ade3306

File tree

4 files changed

+108
-19
lines changed

4 files changed

+108
-19
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:
@@ -235,7 +255,7 @@ def sort_stream(
235255
return changed
236256

237257

238-
def check_stream(
258+
def check_stream( # noqa: PLR0913
239259
input_stream: TextIO,
240260
show_diff: Union[bool, TextIO] = False,
241261
extension: Optional[str] = None,
@@ -255,6 +275,12 @@ def check_stream(
255275
- **file_path**: The disk location where the code string was pulled from.
256276
- **disregard_skip**: set to `True` if you want to ignore a skip set in config for this file.
257277
- ****config_kwargs**: Any config modifications.
278+
279+
Future modifications should consider refactoring to reduce complexity.
280+
281+
* There are currently 6 function argurments vs 5 recommended.
282+
283+
To revalidate these numbers, run `ruff check --select=C901,PLR091`.
258284
"""
259285
config = _config(path=file_path, config=config, **config_kwargs)
260286

@@ -302,7 +328,7 @@ def check_stream(
302328
return False
303329

304330

305-
def check_file(
331+
def check_file( # noqa: PLR0913
306332
filename: Union[str, Path],
307333
show_diff: Union[bool, TextIO] = False,
308334
config: Config = DEFAULT_CONFIG,
@@ -322,6 +348,12 @@ def check_file(
322348
- **disregard_skip**: set to `True` if you want to ignore a skip set in config for this file.
323349
- **extension**: The file extension that contains imports. Defaults to filename extension or py.
324350
- ****config_kwargs**: Any config modifications.
351+
352+
Future modifications should consider refactoring to reduce complexity.
353+
354+
* There are currently 6 function argurments vs 5 recommended.
355+
356+
To revalidate these numbers, run `ruff check --select=C901,PLR091`.
325357
"""
326358
file_config: Config = config
327359

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

isort/settings.py

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,13 +291,21 @@ def __hash__(self) -> int:
291291

292292

293293
class Config(_Config):
294-
def __init__(
294+
def __init__( # noqa: C901,PLR0912,PLR0915
295295
self,
296296
settings_file: str = "",
297297
settings_path: str = "",
298298
config: Optional[_Config] = None,
299299
**config_overrides: Any,
300300
):
301+
"""Future modifications should consider refactoring to reduce complexity.
302+
303+
* The McCabe cyclomatic complexity is currently 15 vs 10 recommended.
304+
* There are currently 7 return statements vs 6 recommended.
305+
* There are currently 16 branches vs 12 recommended.
306+
307+
To revalidate these numbers, run `ruff check --select=C901,PLR091`.
308+
"""
301309
self._known_patterns: Optional[List[Tuple[Pattern[str], str]]] = None
302310
self._section_comments: Optional[Tuple[str, ...]] = None
303311
self._section_comments_end: Optional[Tuple[str, ...]] = None
@@ -586,8 +594,17 @@ def _check_folder_git_ls_files(self, folder: str) -> Optional[Path]:
586594
}
587595
return git_folder
588596

589-
def is_skipped(self, file_path: Path) -> bool:
590-
"""Returns True if the file and/or folder should be skipped based on current settings."""
597+
def is_skipped(self, file_path: Path) -> bool: # noqa: C901,PLR0911,PLR0912
598+
"""Returns True if the file and/or folder should be skipped based on current settings.
599+
600+
Future modifications should consider refactoring to reduce complexity.
601+
602+
* The McCabe cyclomatic complexity is currently 15 vs 10 recommended.
603+
* There are currently 7 return statements vs 6 recommended.
604+
* There are currently 16 branches vs 12 recommended.
605+
606+
To revalidate these numbers, run `ruff check --select=C901,PLR091`.
607+
"""
591608
if self.directory and Path(self.directory) in file_path.resolve().parents:
592609
file_name = os.path.relpath(file_path.resolve(), self.directory)
593610
else:
@@ -824,7 +841,17 @@ def find_all_configs(path: str) -> Trie:
824841
return trie_root
825842

826843

827-
def _get_config_data(file_path: str, sections: Tuple[str, ...]) -> Dict[str, Any]:
844+
def _get_config_data( # noqa: C901,PLR0912,PLR0915
845+
file_path: str, sections: Tuple[str, ...]
846+
) -> Dict[str, Any]:
847+
"""Future modifications should consider refactoring to reduce complexity.
848+
849+
* The McCabe cyclomatic complexity is currently 27 vs 10 recommended.
850+
* There are currently 28 branches vs 12 recommended.
851+
* There are currently 62 statements vs 50 recommended.
852+
853+
To revalidate these numbers, run `ruff check --select=C901,PLR091`.
854+
"""
828855
settings: Dict[str, Any] = {}
829856

830857
if file_path.endswith(".toml"):

isort/wrap.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from .wrap_modes import formatter_from_string, vertical_hanging_indent
88

99

10-
def import_statement(
10+
def import_statement( # noqa: PLR0913
1111
import_start: str,
1212
from_imports: List[str],
1313
comments: Sequence[str] = (),
@@ -16,7 +16,14 @@ def import_statement(
1616
multi_line_output: Optional[Modes] = None,
1717
explode: bool = False,
1818
) -> str:
19-
"""Returns a multi-line wrapped form of the provided from import statement."""
19+
"""Returns a multi-line wrapped form of the provided from import statement.
20+
21+
Future modifications should consider refactoring to reduce complexity.
22+
23+
* There are currently 7 function argurments vs 5 recommended.
24+
25+
To revalidate these numbers, run `ruff check --select=C901,PLR091`.
26+
"""
2027
if explode:
2128
formatter = vertical_hanging_indent
2229
line_length = 1
@@ -68,8 +75,18 @@ def import_statement(
6875
return statement
6976

7077

71-
def line(content: str, line_separator: str, config: Config = DEFAULT_CONFIG) -> str:
72-
"""Returns a line wrapped to the specified line-length, if possible."""
78+
def line(
79+
content: str, line_separator: str, config: Config = DEFAULT_CONFIG
80+
) -> str: # noqa: C901,PLR0912
81+
"""Returns a line wrapped to the specified line-length, if possible.
82+
83+
Future modifications should consider refactoring to reduce complexity.
84+
85+
* The McCabe cyclomatic complexity is currently 14 vs 10 recommended.
86+
* There are currently 15 branches vs 12 recommended.
87+
88+
To revalidate these numbers, run `ruff check --select=C901,PLR091`.
89+
"""
7390
wrap_mode = config.multi_line_output
7491
if len(content) > config.line_length and wrap_mode != Modes.NOQA: # type: ignore
7592
line_without_comment = content

pyproject.toml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,7 @@ lint.select = [
182182
"FLY",
183183
"PERF",
184184
"PIE",
185-
"PLC",
186-
"PLE",
185+
"PL",
187186
"RUF",
188187
"S",
189188
"UP",
@@ -193,15 +192,19 @@ lint.ignore = [
193192
"B017",
194193
"B028",
195194
"B904",
195+
"C901", # REMOVE ME!!
196196
"E203",
197197
"E501",
198198
"PERF203",
199+
"PLR5501",
200+
"PLR091", # REMOVE ME!!
201+
"PLW",
199202
"RUF100",
200203
"UP006",
201204
"UP035",
202205
]
203-
lint.exclude = [ "isort/_vendored/*" ]
204-
lint.mccabe.max-complexity = 91 # Default is 10
206+
lint.exclude = [ "isort/_vendored/*", "isort/deprecated/*" ]
207+
lint.pylint.allow-magic-value-types = [ "bytes", "int", "str" ]
205208

206209
[tool.ruff.lint.per-file-ignores]
207210
"isort/deprecated/finders.py" = [ "UP034" ]
@@ -211,7 +214,8 @@ lint.mccabe.max-complexity = 91 # Default is 10
211214
"isort/setuptools_commands.py" = [ "RUF012" ]
212215
"tests/*" = [ "RUF001", "S" ]
213216
"tests/unit/example_crlf_file.py" = [ "F401" ]
214-
"tests/unit/test_wrap_modes.py" = [ "PIE804" ]
217+
"tests/unit/test_main.py" = [ "PLR0915" ]
218+
"tests/unit/test_wrap_modes.py" = [ "PIE804", "PLR0913" ]
215219

216220
[tool.isort]
217221
profile = "hug"

0 commit comments

Comments
 (0)