File: action_comments.md

package info (click to toggle)
isort 8.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 2,404 kB
  • sloc: python: 14,876; javascript: 42; makefile: 28; sh: 21
file content (117 lines) | stat: -rw-r--r-- 2,552 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# Action Comments

The most basic way to configure the flow of isort within a single file is action comments. These comments are picked up and interpreted by the isort parser during parsing.


## isort: skip_file

Tells isort to skip the entire file.

Example:

```python
# !/bin/python3
# isort: skip_file
import os
import sys

...
```

!!! warning
    This should be placed as high in the file as reasonably possible.
    Since isort uses a streaming architecture, it may have already completed some work before it reaches the comment. Usually, this is okay - but can be confusing if --diff or any interactive options are used from the command line.


## isort: skip

If placed on the same line as (or within the continuation of a) an import statement, isort will not sort this import.
More specifically, it prevents the import statement from being recognized by isort as an import. In consequence, this line will be treated as code and be pushed down to below the import section of the file.

Example:

```python
import 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.

## isort: off

Turns isort parsing off. Every line after an `# isort: off` statement will be passed along unchanged until an `# isort: on` comment or the end of the file.

Example:

```python
import e
import f

# isort: off

import b
import a
```

## isort: on

Turns isort parsing back on. This only makes sense if an `# isort: off` comment exists higher in the file! This allows you to have blocks of unsorted imports, around otherwise sorted ones.

Example:

```python

import e
import f

# isort: off

import b
import a

# isort: on

import c
import d

```

## isort: split

Tells isort the current sort section is finished, and all future imports belong to a new sort grouping.

Example:

```python

import e
import f

# isort: split

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:

```python
import c
import b  # isort: split
import a
```

!!! tip
    isort split is exactly the same as placing an `# isort: on` immediately below an `# isort: off`


## isort: dont-add-imports

Tells isort to not automatically add imports to this file, even if --add-imports is set.

## isort: dont-add-import: [IMPORT_LINE]

Tells isort to not automatically add a particular import, even if --add-imports says to add it.