Repository: psf/black
File: src/black/lines.py (Python)

Code before:
        return block

    def _maybe_empty_lines(self, current_line: Line) -> Tuple[int, int]:  # noqa: C901
        max_allowed = 1
        if current_line.depth == 0:
            max_allowed = 1 if self.mode.is_pyi else 2

        if current_line.leaves:
            # Consume the first leaf's extra newlines.
            first_leaf = current_line.leaves[0]
            before = first_leaf.prefix.count("\n")
            before = min(before, max_allowed)
            first_leaf.prefix = ""
        else:
            before = 0

        user_had_newline = bool(before)
        depth = current_line.depth

        # Mutate self.previous_defs, remainder of this function should be pure
        previous_def = None
        while self.previous_defs and self.previous_defs[-1].depth >= depth:
            previous_def = self.previous_defs.pop()
        if current_line.is_decorator or current_line.is_def or current_line.is_class:
            if not current_line.is_decorator:
                self.previous_defs.append(current_line)

        if self.previous_line is None:
            # Don't insert empty lines before the first line in the file.
            return 0, 0

        if current_line.is_docstring:
            if self.previous_line.is_class:
                return 0, 1
            if self.previous_line.opens_block and self.previous_line.is_def:
                return 0, 0

        if previous_def is not None:
            assert self.previous_line is not None
            if self.mode.is_pyi:
                if previous_def.is_class and not previous_def.is_stub_class:
                    before = 1
                elif depth and not current_line.is_def and self.previous_line.is_def:
                    # Empty lines between attributes and methods should be preserved.
                    before = 1 if user_had_newline else 0
                elif depth:
                    before = 0
                else:
                    before = 1
            else:
                if depth:

Review comment (suggestion):
```suggestion
        if current_line.is_def or current_line.is_class:
            self.previous_defs.append(current_line)
```
This should be equivalent unless I'm missing something

Code after:
        return block

    def _maybe_empty_lines(self, current_line: Line) -> Tuple[int, int]:  # noqa: C901
        max_allowed = 1
        if current_line.depth == 0:
            max_allowed = 1 if self.mode.is_pyi else 2

        if current_line.leaves:
            # Consume the first leaf's extra newlines.
            first_leaf = current_line.leaves[0]
            before = first_leaf.prefix.count("\n")
            before = min(before, max_allowed)
            first_leaf.prefix = ""
        else:
            before = 0

        user_had_newline = bool(before)
        depth = current_line.depth

        # Mutate self.previous_defs, remainder of this function should be pure
        previous_def = None
        while self.previous_defs and self.previous_defs[-1].depth >= depth:
            previous_def = self.previous_defs.pop()
        if current_line.is_def or current_line.is_class:
            self.previous_defs.append(current_line)

        if self.previous_line is None:
            # Don't insert empty lines before the first line in the file.
            return 0, 0

        if current_line.is_docstring:
            if self.previous_line.is_class:
                return 0, 1
            if self.previous_line.opens_block and self.previous_line.is_def:
                return 0, 0

        if previous_def is not None:
            assert self.previous_line is not None
            if self.mode.is_pyi:
                if previous_def.is_class and not previous_def.is_stub_class:
                    before = 1
                elif depth and not current_line.is_def and self.previous_line.is_def:
                    # Empty lines between attributes and methods should be preserved.
                    before = 1 if user_had_newline else 0
                elif depth:
                    before = 0
                else:
                    before = 1
            else:
                if depth:
                    before = 1