From: Alex Vandiver Date: Fri, 8 May 2020 13:08:15 +0000 (-0700) Subject: Re-indent the contents of docstrings (#1053) X-Git-Url: https://git.madduck.net/etc/vim.git/commitdiff_plain/a4c11a75e12300abfbe4c36854e450d42bdd1ee7?ds=sidebyside;hp=a4c11a75e12300abfbe4c36854e450d42bdd1ee7 Re-indent the contents of docstrings (#1053) * Re-indent the contents of docstrings when indentation changes Keeping the contents of docstrings completely unchanged when re-indenting (from 2-space intents to 4, for example) can cause incorrect docstring indentation: ``` class MyClass: """Multiline class docstring """ def method(self): """Multiline method docstring """ pass ``` ...becomes: ``` class MyClass: """Multiline class docstring """ def method(self): """Multiline method docstring """ pass ``` This uses the PEP 257 algorithm for determining docstring indentation, and adjusts the contents of docstrings to match their new indentation after `black` is applied. A small normalization is necessary to `assert_equivalent` because the trees are technically no longer precisely equivalent -- some constant strings have changed. When comparing two ASTs, whitespace after newlines within constant strings is thus folded into a single space. Co-authored-by: Luka Zakrajšek * Extract the inner `_v` method to decrease complexity This reduces the cyclomatic complexity to a level that makes flake8 happy. * Blacken blib2to3's docstring which had an over-indent Co-authored-by: Luka Zakrajšek Co-authored-by: Zsolt Dollenstein ---