Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

change spacing to two instead of four with pep8 or flake8?

2,440 views
Skip to first unread message

Dennis

unread,
Apr 7, 2014, 11:06:34 PM4/7/14
to python-list
Hi,

In Pylint you can change the spacing multiplier from 4 spaces to two
in its pylintrc, but for the life of me I cannot find a way to do this
with the flake8 / pep8 utilities.

I want to avoid ignoring E111 altogether if at all possible, because
it may catch other spacing problems that are not as obvious.

hacky/non-hacky solutions welcome of course.

If this is too specific and I should go to the pep8/flake8 MLs that is
welcome advice too.

Thanks,

Dennis

Chris “Kwpolska” Warrick

unread,
Apr 8, 2014, 3:52:43 AM4/8/14
to Dennis, python-list
> --
> https://mail.python.org/mailman/listinfo/python-list

You are trying to use tools that enforce a set of rules, one of which
is “use 4 spaces per indentation level”. If you don’t agree with this
rule, simply don’t use tools that enforce these rules. It’s that
easy.

But note, that E111 is “indentation is not a multiple of four”. Which
you are never going to listen to anyways if you want 2 spaces per
indentation level. If you *really* want to do 2 spaces (and look
weird), then just ignore that.

--
Chris “Kwpolska” Warrick <http://kwpolska.tk>
PGP: 5EAAEA16
stop html mail | always bottom-post | only UTF-8 makes sense

Tim Chase

unread,
Apr 8, 2014, 7:53:26 AM4/8/14
to Chris “Kwpolska” Warrick, python-list
On 2014-04-08 09:52, Chris “Kwpolska” Warrick wrote:
> On Tue, Apr 8, 2014 at 5:06 AM, Dennis <daod...@gmail.com> wrote:
> > In Pylint you can change the spacing multiplier from 4 spaces to
> > two in its pylintrc, but for the life of me I cannot find a way
> > to do this with the flake8 / pep8 utilities.
> >
> > I want to avoid ignoring E111 altogether if at all possible,
> > because it may catch other spacing problems that are not as
> > obvious.
>
> You are trying to use tools that enforce a set of rules, one of
> which is “use 4 spaces per indentation level”. If you don’t agree
> with this rule, simply don’t use tools that enforce these rules.
> It’s that easy.
>
> But note, that E111 is “indentation is not a multiple of four”.
> Which you are never going to listen to anyways if you want 2 spaces
> per indentation level. If you *really* want to do 2 spaces (and
> look weird), then just ignore that.

It sounds like the OP wants a "indentation is not a multiple of N"
error/warning which would be a more generic (and as you state, look
weird doing so). I wouldn't expect pep8 to do it, since its goal is
to align with pep8. But I could see some of the other checkers
having a command-line option to set the expected indentation.

Otherwise, one might just do something like

sed -n '/^\( \)*\</!{=;p}'

which will print the offending line numbers on one line followed on
the next line by the offending line's contents.

-tkc


Peter Otten

unread,
Apr 8, 2014, 8:55:46 AM4/8/14
to pytho...@python.org
Dennis wrote:

> In Pylint you can change the spacing multiplier from 4 spaces to two
> in its pylintrc, but for the life of me I cannot find a way to do this
> with the flake8 / pep8 utilities.
>
> I want to avoid ignoring E111 altogether if at all possible, because
> it may catch other spacing problems that are not as obvious.
>
> hacky/non-hacky solutions welcome of course.

The check is hardcoded

if indent_char == ' ' and indent_level % 4:
yield 0, "E111 indentation is not a multiple of four"

so your only short-term solution is to modify the script's source code.

Roy Smith

unread,
Apr 8, 2014, 9:20:29 AM4/8/14
to
In article <mailman.9010.1396961...@python.org>,
There's always monkey-patching :-)

Peter Otten

unread,
Apr 8, 2014, 10:06:44 AM4/8/14
to pytho...@python.org
There is always a way to achieve roughly the same that takes more time and
is slightly harder to get right ;)


shivam...@lendbuzz.com

unread,
Jun 28, 2019, 12:45:29 PM6/28/19
to
What file is this?

Cameron Simpson

unread,
Jun 29, 2019, 2:56:09 AM6/29/19
to
On 07Apr2014 20:06, Dennis <daod...@gmail.com> wrote:
>In Pylint you can change the spacing multiplier from 4 spaces to two
>in its pylintrc, but for the life of me I cannot find a way to do this
>with the flake8 / pep8 utilities.
>
>I want to avoid ignoring E111 altogether if at all possible, because
>it may catch other spacing problems that are not as obvious.

I ignore E111 and hope other linters catch stuff it will now miss.

I've also taken to having my files autoformatted with yapf on save,
which makes a lot of formatting more rigorous.

My current lint script runs pyflakes, pep8 and pylint.

My personal lint script:

https://bitbucket.org/cameron_simpson/css/src/tip/bin-cs/lint

My personal format script:

https://bitbucket.org/cameron_simpson/css/src/tip/bin-cs/format

Take what you'd like.

Cheers,
Cameron Simpson <c...@cskk.id.au>

Malcolm Greene

unread,
Jun 29, 2019, 12:19:41 PM6/29/19
to
> I've also taken to having my files auto-formatted with yapf on save ...

@Cameron: Have you considered black at all and if so, what are your thoughts?

Thanks,
Malcolm

Cameron Simpson

unread,
Jun 29, 2019, 7:24:41 PM6/29/19
to
On 29Jun2019 10:19, Malcolm Greene <pyt...@bdurham.com> wrote:
>> I've also taken to having my files auto-formatted with yapf on save ...
>
>@Cameron: Have you considered black at all and if so, what are your
>thoughts?

I did consider black. Its core selling point was its total
inflexibility. Use this and stop _caring_ about the formatting: it will
be PEP8 compliant and readable. It is like "go fmt" in that regard
(Which I use with Go, when I use Go - you can see that in the "format"
script I posted).

The target here is: all code uses the same style, the chosen style is
good (readable, reasonable, acceptable to most people), let's just use
it and spent our time worrying about coding instead of style.

However, I want flexibility.

Like the OP, I use 2 spece indentation and have my own foibles. Here is
the .style.yapf file I use in my personal code:

[style]
based_on_style = pep8
blank_line_before_module_docstring = True
blank_line_before_nested_class_or_def = True
blank_lines_around_top_level_definition = 1
dedent_closing_brackets = True
#indent_dictionary_value = True
indent_width = 2
split_before_expression_after_opening_paren = True
split_before_first_argument = True
split_complex_comprehension = True
space_between_ending_comma_and_closing_bracket = False
split_before_dot = true
use_tabs = False

This comes remarkably close to the style I was hand applying before
biting the bullet and putting in the work required to get my editor to
autoformat on save.

[ Aside: another nice thing about autoformatting, over the "nice!"
feeling one gets seeing the code shuffle around in front of one's face,
is that if there's a syntax error the code _doesn't_ shuffle around and
one can go "whoops" and eyeball the code more closely. ]

Cheers,
Cameron Simpson <c...@cskk.id.au>
0 new messages