Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hanging indent and pylint (PEP8) #769

Open
kamahen opened this issue Oct 15, 2019 · 8 comments
Open

hanging indent and pylint (PEP8) #769

kamahen opened this issue Oct 15, 2019 · 8 comments

Comments

@kamahen
Copy link
Contributor

kamahen commented Oct 15, 2019

pylint doesn't like this indentation -- the 2nd line should be indented an additional 4 spaces:

    if (node.children[0].type == token.AWAIT or
        (node.children[0].type == token.NAME and xcast(Leaf, node.children[0]).value == 'await')):
        atom_child, *trailer_factor_children = node.children[1:]

I couldn't see any option for setting hanging indent -- continuation_indent_width doesn't do what I want.

Here's another example that pylint doesn't like -- the 2nd line should be indented an additional 4 spaces:

def _as_prolog_str_full(
    value: Union[PlainOldData, List[Any], bool, str, int, Dict[Any, Any], None, Exception]
) -> str:
    """Recursively turn an object into a Prolog term."""
@andreasvc
Copy link

The documentation explains that this is because continuation_align_style=FIXED does not work together with use_tabs=False. I was actually just wondering why not?--because I'd like that option as well.

@kamahen
Copy link
Contributor Author

kamahen commented Oct 21, 2019

Can you please point me to the documentation for continuation_align_style=FIXED not working with use_tabs=False?

I tried continuation_align_style=FIXED with use_tabs=False and it seemed to work and produced the same output as continuation_align_style=SPACE ... so I'm confused what this option does ...

(So, I still haven't figured out how to get PEP8-style extra indentation for continued if statements and continued function definitions.)

@andreasvc
Copy link

Search for "CONTINUATION_ALIGN_STYLE" in README.rst.

Again, with use_tabs=False the option simply does not work, as documented. Set use_tabs to True to see what the option does.

There is a difference between PEP8-style continuations (aligned with bracket on previous row) and the continuations suggested by pylint (indented with one extra indent). The latter style looks as follows:

if (node.children[0].type == token.AWAIT or
        (node.children[0].type == token.NAME and xcast(Leaf, node.children[0]).value == 'await')):
    atom_child, *trailer_factor_children = node.children[1:]

And

def _as_prolog_str_full(
        value: Union[PlainOldData, List[Any], bool, str, int, Dict[Any, Any], None, Exception]) -> str:
    """Recursively turn an object into a Prolog term."""

@kamahen
Copy link
Contributor Author

kamahen commented Oct 21, 2019

I've read that section a dozen times and I simply cannot understand it. :(
(And the sentence "For options FIXED, and VALIGN-RIGHT are only available when USE_TABS is enabled." isn't grammatical.)

The examples of PEP8 indentation seem to show the same style that pylint wants, and which pytype doesn't do (at least, it doesn't do with use_tabs=False)

@andreasvc
Copy link

I agree, that sentence does not look grammatical and it's weird that this combination of options is not available. You're right, PEP8 discusses three possible continuation styles. My favorite is to always stick to the second one (indent with one extra level of indentation, to clearly separate continuation from regular indentation).

@kamahen
Copy link
Contributor Author

kamahen commented Oct 22, 2019

@gwelymernans - Does it make sense to add another CONTINUATION_INDENT_WIDTH knob, that gives extra indent as in examples of PEP8 indentation?

@yinyin - Could you please fix the sentence "For options FIXED, and VALIGN-RIGHT are only available when USE_TABS is enabled."? (Should it just be "(ptions FIXED and VALIGN-RIGHT are only available when USE_TABS is enabled."?)
And also please explain why you decided that options FIXED and VALIGN-RIGHT are only available when USE_TABS is enabled?

@yinyin
Copy link
Contributor

yinyin commented Oct 24, 2019

@kamahen I made a PR to enable CONTINUATION_ALIGN_STYLE = FIXED for space indent.

At the time I add the knob, I did not aware this option is useful for indentation with spaces.

@bwendling
Copy link
Member

Sorry for missing this. Let me look into this to see if there's a fix I can quickly apply.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants