Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit eedfc38
Author: Jason R. Coombs <jaraco@jaraco.com>
Date:   Fri May 19 13:00:29 2023 -0400

    Avoid EncodingWarning in blib2to3 (psf#3696)

commit 2fd9d8b
Author: Jonathan Berthias <jvberthias@gmail.com>
Date:   Fri May 19 01:57:17 2023 +0200

    Remove blank lines before class docstring (psf#3692)

commit db3668a
Author: Ray Bell <rayjohnbell0@gmail.com>
Date:   Tue May 16 22:47:45 2023 -0400

    Sort DEFAULT_EXCLUDES and add .vscode, .pytest_cache and .ruff_cache (psf#3691)

    Co-authored-by: Ray Bell <ray.bell@dtn.com>
  • Loading branch information
jsh9 committed May 21, 2023
1 parent 4969e7d commit f238168
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Expand Up @@ -16,11 +16,14 @@

- Implicitly concatenated strings used as function args are no longer wrapped inside
parentheses (#3640)
- Remove blank lines between a class definition and its docstring (#3692)

### Configuration

<!-- Changes to how Black can be configured -->

- `.pytest_cache`, `.ruff_cache` and `.vscode` are now excluded by default (#3691)

### Packaging

<!-- Changes to how Black is packaged, such as dependency requirements -->
Expand Down
3 changes: 1 addition & 2 deletions src/blib2to3/pgen2/pgen.py
Expand Up @@ -30,7 +30,6 @@ class PgenGrammar(grammar.Grammar):


class ParserGenerator(object):

filename: Path
stream: IO[Text]
generator: Iterator[GoodTokenInfo]
Expand All @@ -39,7 +38,7 @@ class ParserGenerator(object):
def __init__(self, filename: Path, stream: Optional[IO[Text]] = None) -> None:
close_stream = None
if stream is None:
stream = open(filename)
stream = open(filename, encoding="utf-8")
close_stream = stream.close
self.filename = filename
self.stream = stream
Expand Down
2 changes: 2 additions & 0 deletions src/cercis/lines.py
Expand Up @@ -696,6 +696,8 @@ def _maybe_empty_lines(self, current_line: Line) -> Tuple[int, int]:
and self.previous_line.is_class
and current_line.is_triple_quoted_string
):
if Preview.no_blank_line_before_class_docstring in current_line.mode:
return 0, 1
return before, 1

if self.previous_line and self.previous_line.opens_block:
Expand Down
1 change: 1 addition & 0 deletions src/cercis/mode.py
Expand Up @@ -170,6 +170,7 @@ class Preview(Enum):
hex_codes_in_unicode_sequences = auto()
improved_async_statements_handling = auto()
multiline_string_handling = auto()
no_blank_line_before_class_docstring = auto()
prefer_splitting_right_hand_side_of_assignments = auto()
# NOTE: string_processing requires wrap_long_dict_values_in_parens
# for https://github.com/psf/black/issues/3117 to be fixed.
Expand Down
58 changes: 58 additions & 0 deletions tests/data/preview/no_blank_line_before_docstring.py
@@ -0,0 +1,58 @@
def line_before_docstring():

"""Please move me up"""


class LineBeforeDocstring:

"""Please move me up"""


class EvenIfThereIsAMethodAfter:

"""I'm the docstring"""
def method(self):
pass


class TwoLinesBeforeDocstring:


"""I want to be treated the same as if I were closer"""


class MultilineDocstringsAsWell:

"""I'm so far
and on so many lines...
"""


# output


def line_before_docstring():
"""Please move me up"""


class LineBeforeDocstring:
"""Please move me up"""


class EvenIfThereIsAMethodAfter:
"""I'm the docstring"""

def method(self):
pass


class TwoLinesBeforeDocstring:
"""I want to be treated the same as if I were closer"""


class MultilineDocstringsAsWell:
"""I'm so far
and on so many lines...
"""

0 comments on commit f238168

Please sign in to comment.