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"}
}
}
7
5 comments

This has been puzzling me for a while too.

0
Avatar
Nickolaus Fuerstenberg

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
Avatar
Nickolaus Fuerstenberg

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
Avatar
Paolo Matias Lammens

I have the same issue. My indents are 4 spaces, and continuation indents are 2. However, reformatting this

assert eggs == \
  spam

gets reformatted into this

assert eggs == \
    spam

yielding the PEP8 error "continuation line over indented for visual indent". Isn't that a continuation indent and thus it should be 2 spaces?

Is there a YouTrack page for this?

0

Please sign in to leave a comment.