black/blib2to3
Alex Vandiver a4c11a75e1
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 <luka@bancek.net>

* 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 <luka@bancek.net>
Co-authored-by: Zsolt Dollenstein <zsol.zsol@gmail.com>
2020-05-08 14:08:15 +01:00
..
pgen2 Improve String Handling (#1132) 2020-05-08 14:56:21 +02:00
__init__.py Blacken .py files in blib2to3 (#1011) 2019-10-20 15:55:31 +02:00
Grammar.txt Support py38-style starred expressions in return statement (#1121) 2020-01-18 07:21:46 -08:00
LICENSE Link to GitHub + HTTPS + typos (#303) 2018-06-06 09:50:08 -07:00
PatternGrammar.txt Initial commit 2018-03-14 12:55:32 -07:00
pygram.py Support compilation with mypyc (#1009) 2019-10-30 07:29:29 -07:00
pytree.py Re-indent the contents of docstrings (#1053) 2020-05-08 14:08:15 +01:00
README Changes default logger used by blib2to3 Driver (#732) 2019-03-14 13:39:42 +01:00

A subset of lib2to3 taken from Python 3.7.0b2.
Commit hash: 9c17e3a1987004b8bcfbe423953aad84493a7984

Reasons for forking:
- consistent handling of f-strings for users of Python < 3.6.2
- backport of BPO-33064 that fixes parsing files with trailing commas after
  *args and **kwargs
- backport of GH-6143 that restores the ability to reformat legacy usage of
  `async`
- support all types of string literals
- better ability to debug (better reprs)
- INDENT and DEDENT don't hold whitespace and comment prefixes
- ability to Cythonize

Change Log:
- Changes default logger used by Driver