yapf: use_tabs=True does not work for lists and dictionaries

We use_tabs for indentation but continuation_indent_width still uses spaces instead of tabs for lists and dictionaries that are split over multiple lines. If required there should be a separate knob for this which allows setting of tabs vs spaces for lists and dictionaries

``

About this issue

  • Original URL
  • State: open
  • Created 7 years ago
  • Reactions: 1
  • Comments: 33 (13 by maintainers)

Most upvoted comments

@gwelymernans, there are 2 basic school of thoughts (amongst us tabbers=tab users) for continuation alignment

  • Tab only (for both indentation and alignment) In this case whenever continuing on a long line, there will be an additional tab like in the 1st screenshot of @gregwym
  • Tab and space indentation (tab for code indentation and tab+spaces for alignment) In this case the tab indentation used for the primary line is retained and further indentation is done through spaces. This keeps the code aligned regardless of the tab to space display being used on a particular display/IDE and works well for those who use it.

Currently yapf does a very unexpected switchover back to pure spaces for continuation indentation which is probably completely invalid for any tabber.

If yapf has to truly cater to tab users, it will probably have to have a flag for those of us in the 2nd school of mixed indentation

hope I have helped

Thanks for not starting a ‘holy war’ on this 👍 . Ideally, though this may vary even amongst us ‘tabs’ people, I think I would want the continuation indent to be additional to the indent at which the code is at right now. so CONTINUATION_INDENT=1 should result in the code below Eg below

def a():
	really_long_dictionary_name = {
		first_really_long_key: 1,
		second_really_long_key: 2,
	}

SPACE and FIXED are reasonable options. LESS and MORE just don’t make sense to me. When would that ever be useful? The major point of using tabs is that their width can be customized in the editor.

I decided to get with PEP 8 and switch to spaces. It feels wrong/strange but I need to go with the flow here. So I reconfigured my IDE to use spaces, and yapf is off my bad list. Adapt or die. 😃

@ichibrosan, I think you mean conform or die, I say NEVER 😃

Greg literally wrote this in the last message (VS code).

On the topic of this issue, I think it is strange that E101 reports spaces used for vertical alignment. Vertical alignment is used in PEP8 and there is no reasonable way of aligning things vertically like that without tabs. There is really two types of indentation in programming: scope indentation and indentation used for line continuation.

Other style guides (not PEP8) require not using vertical alignment, because this can a single line change to have a “blast radius” to other lines. Having a setting to use only a single tab for line continuation is not unreasonable.

Personally, I am happy with the current functionality.

On Fri, Feb 9, 2018 at 1:07 PM Anshuman Aggarwal notifications@github.com wrote:

Sorry to spam everyone but @gregwym https://github.com/gregwym…what IDE/editor is this?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/google/yapf/issues/380#issuecomment-364416606, or mute the thread https://github.com/notifications/unsubscribe-auth/AAvI0dJu7DAV2syvyK4ueLneYgGvu50aks5tTDTkgaJpZM4MX7RG .

Yes, E101 also apply to continuation indentations. There isn’t space mixed within tabs like \t \t in my example as you can see all invisible chars in the screenshots. (I’m using Visual Studio Code.) One tab per indentation level is the way to go.

For your example, we can format like this. image

Or like this, without enclosing bracket. image

But not with space 😦 image

The behavior of current implementation in master is also weird for condition without enclosing bracket: image

I agree with @eskhool: an opening character (brace, bracket, etc.) give me an extra indent (ie. tab) on the next line. As a “tabber” too, I can not understand the trend to do ASCII-art and space based alignment 😃, where you break everything each time you change a name…

Nonetheless, thank you for yapf