Repository: ipython/ipython

Issue:
Fix prompt backward compat.
see #14223


Discussion:

Resolving patch:
diff --git a/IPython/terminal/interactiveshell.py b/IPython/terminal/interactiveshell.py
--- a/IPython/terminal/interactiveshell.py
+++ b/IPython/terminal/interactiveshell.py
@@ -3,6 +3,7 @@
 import asyncio
 import os
 import sys
+import inspect
 from warnings import warn
 from typing import Union as UnionType, Optional
 
@@ -66,8 +67,8 @@
 PTK3 = ptk_version.startswith('3.')
 
 
-class _NoStyle(Style): pass
-
+class _NoStyle(Style):
+    pass
 
 
 _style_overrides_light_bg = {
@@ -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']
@@ -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,
diff --git a/examples/Embedding/embed_class_long.py b/examples/Embedding/embed_class_long.py
--- a/examples/Embedding/embed_class_long.py
+++ b/examples/Embedding/embed_class_long.py
@@ -18,26 +18,26 @@
 # %run example-embed.py)
 
 from IPython.terminal.prompts import Prompts, Token
+from traitlets.config.loader import Config
 
 class CustomPrompt(Prompts):
 
-    def in_prompt_tokens(self, cli=None):
+    def in_prompt_tokens(self):
 
-       return [
+        return [
             (Token.Prompt, 'In <'),
             (Token.PromptNum, str(self.shell.execution_count)),
             (Token.Prompt, '>: '),
             ]
 
     def out_prompt_tokens(self):
-       return [
+        return [
             (Token.OutPrompt, 'Out<'),
             (Token.OutPromptNum, str(self.shell.execution_count)),
             (Token.OutPrompt, '>: '),
         ]
  
 
-from traitlets.config.loader import Config
 try:
     get_ipython
 except NameError:
diff --git a/examples/utils/cwd_prompt.py b/examples/utils/cwd_prompt.py
--- a/examples/utils/cwd_prompt.py
+++ b/examples/utils/cwd_prompt.py
@@ -6,9 +6,9 @@
 
 class MyPrompt(Prompts):
 
-     def in_prompt_tokens(self, cli=None):
-         return [(Token, os.getcwd()),
-                 (Token.Prompt, '>>>')]
+    def in_prompt_tokens(self):
+        return [(Token, os.getcwd()), (Token.Prompt, ">>>")]
+
 
 def load_ipython_extension(shell):
     new_prompts = MyPrompt(shell)
@@ -20,7 +20,3 @@ def unload_ipython_extension(shell):
         print("cannot unload")
     else:
         shell.prompts = shell.prompts.old_prompts
-
-
-
-


Test patch: