Skip to content
Merged
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: 1 addition & 5 deletions docs/configuration/action_comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Example:

```python
import b
import a # isort: skip <- this will now stay below b
import a # isort: skip <- this will now stay below b
```
!!! note
It is recommended to where possible use `# isort: off` and `# isort: on` or `# isort: split` instead as the behavior is more explicit and predictable.
Expand Down Expand Up @@ -60,7 +60,6 @@ Turns isort parsing back on. This only makes sense if an `# isort: off` comment
Example:

```python

import e
import f

Expand All @@ -73,7 +72,6 @@ import a

import c
import d

```

## isort: split
Expand All @@ -83,7 +81,6 @@ Tells isort the current sort section is finished, and all future imports belong
Example:

```python

import e
import f

Expand All @@ -93,7 +90,6 @@ import a
import b
import c
import d

```

You can also use it inline to keep an import from having imports above or below it swap position:
Expand Down
2 changes: 1 addition & 1 deletion docs/configuration/custom_sections_and_ordering.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,6 @@ import b
You can even tell isort to always place from imports on top, instead of the default of placing them on bottom, using [from first](./options.md#from-first).

```python
from b import b # If from first is set to True, all from imports will be placed before non-from imports.
from b import b # If from first turnrf on, all from imports are placed before non-from imports.
import a
```
1 change: 1 addition & 0 deletions docs/major_releases/introducing_isort_5.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ It also allows you to place code in-between imports without any hacks required.
```python
import a
import b

...
# more code!
```
Expand Down
4 changes: 2 additions & 2 deletions isort/_parse_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def skip_line(line: str, in_quote: str, needs_import: bool = True) -> SkipLineRe
break
char_index += 1

if ";" in line.split("#")[0] and needs_import:
if ";" in line.split("#", maxsplit=1)[0] and needs_import:
for part in (part.strip() for part in line.split(";")):
if (
part
Expand Down Expand Up @@ -104,7 +104,7 @@ def collect_import_continuation(
extra_lines: list[ExtraLine] = []

if "(" in line.split("#", 1)[0]:
while not line.split("#")[0].strip().endswith(")"):
while not line.split("#", maxsplit=1)[0].strip().endswith(")"):
try:
line, comment = get_next_line()
except StopIteration:
Expand Down
2 changes: 1 addition & 1 deletion isort/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,7 @@ def _separate_packages(section_output: list[str], config: Config) -> list[str]:
package_depth = len(reason.split(".")) - 1 # minus 1 for re.compile
key = ".".join(package_name.split(".")[: package_depth + 1])
else:
key = package_name.split(".")[0]
key = package_name.split(".", maxsplit=1)[0]

if key not in group_keys:
if group_keys:
Expand Down
2 changes: 1 addition & 1 deletion isort/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ def _get_next_line() -> tuple[str, str | None]:
):
trailing_commas.add(import_from)
else:
assert type_of_import == "straight" # noqa: S101 # Only needed for type checker
assert type_of_import == "straight" # noqa: S101 # nosec # Only for type checker
if comments and attach_comments_to is not None:
attach_comments_to.extend(comments)
comments = []
Expand Down
4 changes: 3 additions & 1 deletion isort/wrap_modes.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,9 @@ def _vertical_grid_common(need_trailing_char: bool, **interface: Any) -> str:
while interface["imports"]:
next_import = interface["imports"].pop(0)
next_statement = f"{interface['statement']}, {next_import}"
current_line_length = len(next_statement.split(interface["line_separator"])[-1])
current_line_length = len(
next_statement.rsplit(interface["line_separator"], maxsplit=1)[-1]
)
if interface["imports"] or interface["include_trailing_comma"]:
# We need to account for a comma after this import.
current_line_length += 1
Expand Down
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ docs = [
max-line-length = 100
# Ignore non PEP 8 compliant rules as suggested by black
# E203: https://github.com/psf/black/blob/3fab5ade71bccf80ae0a5af76729099869adea56/docs/the_black_code_style/current_style.md#slices
extend-ignore = [ "E203" ]
# B042: Weird rule that requires random arguments to be passed, without clear benefit
extend-ignore = [ "E203", "B042" ]
exclude = "_vendored"
per-file-ignores = [
"tests/unit/example_crlf_file.py:F401",
Expand Down Expand Up @@ -198,6 +199,7 @@ lint.ignore = [
]
lint.exclude = [ "isort/_vendored/*" ]
lint.mccabe.max-complexity = 91 # Default is 10
format.exclude = [ "README.md", "docs/configuration/multi_line_output_modes.md"]

[tool.ruff.lint.per-file-ignores]
"isort/hooks.py" = [ "S603" ]
Expand Down
738 changes: 470 additions & 268 deletions uv.lock

Large diffs are not rendered by default.

Loading