Reformat code doesn't honor continuation indents

In PyCharm when I 'Reformat Code' it creates 'PEP8: continuation line under-indented for hanging indent' warnings, which requires me to manually clean up the problem. Why doesn't 'Reformat Code' honor what I've set in my preferences?

Preferences > Editor > Code Style > Python 
Tab size: 2, Indent: 2, Continuation Indent: 4

Before (4 spaces, no warnings):

svc_schema = {
"$schema": "http://json-schema.org/draft-03/schema",
"properties": {
"circuit_id": {"required": True, "type": "string"},
"port_type": {"required": True, "type": "string"},
"profile": {"required": True, "type": "string"},
"service_id": {"required": True, "type": "string"},
"status": {"required": False, "type": "string"}
}
}

After 'Reformat Code' (2 spaces, now with PEP8 warnings):

svc_schema = {
"$schema": "http://json-schema.org/draft-03/schema",
"properties": {
"circuit_id": {"required": True, "type": "string"},
"port_type": {"required": True, "type": "string"},
"profile": {"required": True, "type": "string"},
"service_id": {"required": True, "type": "string"},
"status": {"required": False, "type": "string"}
}
}
4 comments

This has been puzzling me for a while too.

0

I am experiencing this issue in Java.

0

Please provide screenshot of your settings under **File | Settings | Editor | Code Style | Python > Tabs and Indents**. I will try to reproduce.

0

Hi Andrey, thanks for the reply.

Please note, I am working in Java: you specified a Python settings page. I accidentally discovered how to resolve my issue and posted here with my solution: https://intellij-support.jetbrains.com/hc/en-us/community/posts/206466649-Continuation-indent-does-not-work. Here is a screenshot of my settings for Java:

 

0

Please sign in to leave a comment.