[Python-ideas] A directive for indentation type, stricter indentation parsing.

Mikhail V mikhailwas at gmail.com
Tue Mar 26 06:48:48 EDT 2019

On Tue, Mar 26, 2019 at 7:04 AM fhsxfhsx <fhsxfhsx at 126.com> wrote:
> Just as to your example, you can try `textwrap.dedent`
Procedural removal is not cool, because it does not know the parent indentation
of the statement that contains the text block, thus it can't resolve
string indents  that were intentionally indented to include extra space.

E.g. this, where "s=" line is already inside an indented block:
    s = """

Say I use 1 tab for 1 indent - what I want here is to remove 1 tab from
each string line AND 1 tab that belongs to code formatting (current indent
of the "s=" line). And if you try to guess it from the string  itself -
it is impossible to resolve all cases, because you still need some criteria
- for example you could use criteria "minimal indent inside the string
is the indent" but
this will again fail if you want extra shift on same level inside the string.
E.g. this:
    s = """

Here I do not want to remove all indents but only as in above - only 1
level inside string
and 1 from parent line.
Do you get it?

So in other words if I want my string blocks aligned within containing
blocks, it  becomes
impossible to resolve all un-indenting cases automatically.


More information about the Python-ideas mailing list