def _(event: E) -> None:
        """
        Behaviour of the Enter key.

        Auto indent after newline/Enter.
        (When not in Vi navigation mode, and when multiline is enabled.)
        """
        b = event.current_buffer
        empty_lines_required = python_input.accept_input_on_enter or 10000

        def at_the_end(b: Buffer) -> bool:
            """we consider the cursor at the end when there is no text after
            the cursor, or only whitespace."""
            text = b.document.text_after_cursor
            return text == "" or (text.isspace() and "\n" not in text)

        if python_input.paste_mode:
            # In paste mode, always insert text.
            b.insert_text("\n")

        elif at_the_end(b) and b.document.text.replace(" ", "").endswith(
            "\n" * (empty_lines_required - 1)
        ):
            # When the cursor is at the end, and we have an empty line:
            # drop the empty lines, but return the value.
            if b.validate():
                b.document = Document(
                    text=b.text.rstrip(), cursor_position=len(b.text.rstrip())
                )

                b.validate_and_handle()
        else:
            auto_newline(b)

        Behaviour of the Enter key.

        Auto indent after newline/Enter.
        (When not in Vi navigation mode, and when multiline is enabled.)
        
src/ptpython/key_bindings.py