comprehension identation

Answered

i have the following auto formatted code:

[
item
for item in
some_list
if (
another_condition
or third_condition
) and condition
]

i would like it to be formatted like:

[
item
for item in
some_list
if (
another_condition
or third_condition
) and condition
]

similar problem:

[
item
for item in
some_list
if condition and (
another_condition
or third_condition
)
]

should be:

[
item
for item in
some_list
if condition and (
another_condition
or third_condition
)
]

Is this possible? what settings are required?

code style export:

<code_scheme name="Project" version="173">
<Python>
<option name="ALIGN_COLLECTIONS_AND_COMPREHENSIONS" value="false" />
<option name="NEW_LINE_AFTER_COLON" value="true" />
<option name="DICT_WRAPPING" value="2" />
<option name="DICT_NEW_LINE_BEFORE_RIGHT_BRACE" value="true" />
<option name="FROM_IMPORT_NEW_LINE_AFTER_LEFT_PARENTHESIS" value="true" />
<option name="FROM_IMPORT_NEW_LINE_BEFORE_RIGHT_PARENTHESIS" value="true" />
<option name="FROM_IMPORT_PARENTHESES_FORCE_IF_MULTILINE" value="true" />
</Python>
<codeStyleSettings language="Python">
<option name="ALIGN_MULTILINE_PARAMETERS" value="false" />
<option name="ALIGN_MULTILINE_PARAMETERS_IN_CALLS" value="false" />
<indentOptions>
<option name="CONTINUATION_INDENT_SIZE" value="4" />
</indentOptions>
</codeStyleSettings>
</code_scheme>
0
3 comments

It seems you are looking for Continuation indent in Preferences | Editor | Code Style | Python

Changing it to 4 should do the trick.

0

it should already be 4.

looks correct in the export too:

<option name="CONTINUATION_INDENT_SIZE" value="4" />
0

my default code style:

<code_scheme name="Default" version="173">
<Python>
<option name="SPACE_AROUND_EQ_IN_NAMED_PARAMETER" value="true" />
<option name="SPACE_AROUND_EQ_IN_KEYWORD_ARGUMENT" value="true" />
<option name="ALIGN_COLLECTIONS_AND_COMPREHENSIONS" value="false" />
<option name="NEW_LINE_AFTER_COLON" value="true" />
<option name="USE_CONTINUATION_INDENT_FOR_ARGUMENTS" value="true" />
<option name="USE_CONTINUATION_INDENT_FOR_COLLECTION_AND_COMPREHENSIONS" value="true" />
<option name="FROM_IMPORT_NEW_LINE_AFTER_LEFT_PARENTHESIS" value="true" />
<option name="FROM_IMPORT_NEW_LINE_BEFORE_RIGHT_PARENTHESIS" value="true" />
<option name="FROM_IMPORT_PARENTHESES_FORCE_IF_MULTILINE" value="true" />
</Python>
<codeStyleSettings language="JSON">
<indentOptions>
<option name="INDENT_SIZE" value="4" />
<option name="CONTINUATION_INDENT_SIZE" value="4" />
</indentOptions>
</codeStyleSettings>
<codeStyleSettings language="JavaScript">
<indentOptions>
<option name="INDENT_SIZE" value="2" />
<option name="CONTINUATION_INDENT_SIZE" value="2" />
<option name="TAB_SIZE" value="2" />
</indentOptions>
</codeStyleSettings>
<codeStyleSettings language="Python">
<option name="RIGHT_MARGIN" value="140" />
<option name="BLANK_LINES_AFTER_IMPORTS" value="2" />
<indentOptions>
<option name="CONTINUATION_INDENT_SIZE" value="4" />
</indentOptions>
</codeStyleSettings>
<codeStyleSettings language="TypeScript">
<indentOptions>
<option name="INDENT_SIZE" value="2" />
<option name="CONTINUATION_INDENT_SIZE" value="2" />
<option name="TAB_SIZE" value="2" />
</indentOptions>
</codeStyleSettings>
</code_scheme>
0

Please sign in to leave a comment.