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 options on continuation lines #63

Open
keyonvafa opened this issue May 29, 2020 · 7 comments
Open

Hanging indent options on continuation lines #63

keyonvafa opened this issue May 29, 2020 · 7 comments
Labels
enhancement New feature or request indentation pull requests welcome PRs will be reviewed, but maintainers will not fix.

Comments

@keyonvafa
Copy link

keyonvafa commented May 29, 2020

First of all, I love this extension. It has made using VS Code such a breeze, so thank you immensely for making it available.

This may be closer to a feature request, but it would be great to have indentation options for continuation lines. There are no hard and fast rules here, but some linters call for four spaces for indents on continuation lines (e.g. Flake8 E121). That is, some linters call for using two tabs on new lines as opposed to one. To be concrete,

Minimal code example:

What the code looks like before pressing enter:

long_variable_name = long_function_name(|)

What I want the code to look like after pressing enter:

long_variable_name = long_function_name(
    |
)

What the code actually looks like after pressing enter:

long_variable_name = long_function_name(
  |
)

Obviously this is subject to personal taste, but it would be great to have indentation options so e.g. the Flake8 preference could be applied by default, if desired by the user. Thanks a lot!

@kbrose
Copy link
Owner

kbrose commented May 30, 2020

It looks like you've set your indentation size in VSCode to 2 spaces, is that correct? The problem is that flake8 only works with an indentation size of 4 spaces.

Just googling around, it looks like this package may handle your use case: https://pypi.org/project/flake8-tabs/

There also seems to be an open PR in flake8 here: https://gitlab.com/pycqa/flake8/-/merge_requests/167

@keyonvafa
Copy link
Author

Thanks for the response. Indeed my indentation size in VSCode is 2 spaces.

The current behavior of the linter is fine by me. I'm trying to get the editor itself to automatically add 2 tabs (i.e. 4 spaces) when I add a new line on an open parenthesis. I'm doing this to follow the Tensorflow style guide (e.g. Colab's editor follows the desired behavior). But I understand this is a pretty niche use case.

@kbrose
Copy link
Owner

kbrose commented May 30, 2020

The tensorflow style guide tells you to "follow the PEP 8 Python style guide, except TensorFlow uses 2 spaces instead of 4".

PEP8 says that continuation lines should use "an extra level of indentation", which in your case is 2 spaces, i.e. the current behavior.

@kbrose
Copy link
Owner

kbrose commented May 30, 2020

Flake8 isn't calling for you to have two levels of indentation, it just expects you to be using four spaces instead of two. That's why I linked you to those two pieces of information on getting flake8 to handle two-space-indentations correctly.

@keyonvafa
Copy link
Author

Thank you for following up. I think the Tensorflow style guide is ambiguous as to when tabs should be 2 spaces. I know Colab and Tensorflow source code use 2 spaces for most tabs but 4 spaces on continuation line indents. But I also understand that PEP 8 only expects one level of indentation.

Regardless of which level of indentation is preferred, it would be great to have the ability to customize continuation line indents, if possible.

@kbrose
Copy link
Owner

kbrose commented May 30, 2020

Someone should update the TF style guide to be accurate, they're not following PEP8. And, in my opinion, their double-indent-for-continuations might just be the dumbest python style convention I've ever seen.

I'm not going to work on this, but feel free to submit a pull request. If you do please write good unit tests -- each additional configuration that is added to this extension exponentially increases the amount of manual testing I do before a new release. I need to be sure it has good automated tests backing up my manual testing.

@kbrose kbrose added enhancement New feature or request pull requests welcome PRs will be reviewed, but maintainers will not fix. labels May 30, 2020
@keyonvafa
Copy link
Author

Got it, thank you! I'll probably hold off on a pull request for now, but I'll let you know if I end up working on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request indentation pull requests welcome PRs will be reviewed, but maintainers will not fix.
Projects
None yet
Development

No branches or pull requests

2 participants