Skip to content

Commit

Permalink
Inspect continuation prompt signature and pass only viable arguments.
Browse files Browse the repository at this point in the history
Closes #14273
  • Loading branch information
Carreau committed Dec 27, 2023
1 parent 46a3714 commit 96afe65
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
23 changes: 20 additions & 3 deletions IPython/terminal/interactiveshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import asyncio
import os
import sys
import inspect
from warnings import warn
from typing import Union as UnionType, Optional

Expand Down Expand Up @@ -66,8 +67,8 @@
PTK3 = ptk_version.startswith('3.')


class _NoStyle(Style): pass

class _NoStyle(Style):
pass


_style_overrides_light_bg = {
Expand All @@ -84,6 +85,20 @@ class _NoStyle(Style): pass
Token.OutPromptNum: '#ansired bold',
}


def _backward_compat_continuation_prompt_tokens(method, width: int, *, lineno: int):
"""
Sagemath use custom prompt and we broke them in 8.19.
"""
sig = inspect.signature(method)
if "lineno" in inspect.signature(method).parameters or any(
[p.kind == p.VAR_KEYWORD for p in sig.parameters.values()]
):
return method(width, lineno=lineno)
else:
return method(width)


def get_default_editor():
try:
return os.environ['EDITOR']
Expand Down Expand Up @@ -764,7 +779,9 @@ def get_message():
"message": get_message,
"prompt_continuation": (
lambda width, lineno, is_soft_wrap: PygmentsTokens(
self.prompts.continuation_prompt_tokens(width, lineno=lineno)
_backward_compat_continuation_prompt_tokens(
self.prompts.continuation_prompt_tokens, width, lineno=lineno
)
)
),
"multiline": True,
Expand Down
2 changes: 1 addition & 1 deletion docs/source/config/details.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ which defines the defaults. The required interface is like this:
:class:`~.TerminalInteractiveShell` instance.

.. method:: in_prompt_tokens(cli=None)
continuation_prompt_tokens(self, cli=None, width=None)
continuation_prompt_tokens(self, width=None)
rewrite_prompt_tokens()
out_prompt_tokens()

Expand Down

0 comments on commit 96afe65

Please sign in to comment.