From 475179a53af1948ca726de1b11d4cdbe2aa90e58 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C5=81ukasz=20Langa?= Date: Fri, 23 Mar 2018 08:56:55 -0700 Subject: [PATCH 1/1] Omit extra space in Sphinx auto-attribute comments This feature of Sphinx is described in: http://www.sphinx-doc.org/en/stable/ext/autodoc.html#directive-autoattribute Fixes #68 --- README.md | 3 +++ black.py | 2 +- tests/comments.py | 20 ++++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 014780b..5d3b118 100644 --- a/README.md +++ b/README.md @@ -324,6 +324,9 @@ More details can be found in [CONTRIBUTING](CONTRIBUTING.md). * omit extra space in kwarg unpacking if it's the first argument (#46) +* omit extra space in [Sphinx auto-attribute comments](http://www.sphinx-doc.org/en/stable/ext/autodoc.html#directive-autoattribute) + (#68) + ### 18.3a3 diff --git a/black.py b/black.py index 7ca6bc6..f03c4f1 100644 --- a/black.py +++ b/black.py @@ -1183,7 +1183,7 @@ def make_comment(content: str) -> str: if content[0] == '#': content = content[1:] - if content and content[0] not in {' ', '!', '#'}: + if content and content[0] not in ' !:#': content = ' ' + content return '#' + content diff --git a/tests/comments.py b/tests/comments.py index 34b38fe..42e42f5 100644 --- a/tests/comments.py +++ b/tests/comments.py @@ -49,6 +49,26 @@ GLOBAL_STATE = {'a': a(1), 'b': a(2), 'c': a(3)} # This time two lines. +class Foo: + """Docstring for class Foo. Example from Sphinx docs.""" + + #: Doc comment for class attribute Foo.bar. + #: It can have multiple lines. + bar = 1 + + flox = 1.5 #: Doc comment for Foo.flox. One line only. + + baz = 2 + """Docstring for class attribute Foo.baz.""" + + def __init__(self): + #: Doc comment for instance attribute qux. + self.qux = 3 + + self.spam = 4 + """Docstring for instance attribute spam.""" + + @fast(really=True) async def wat(): async with X.open_async() as x: # Some more comments -- 2.39.5