Skip to content

Commit

Permalink
Deprecate inputtransformer since 7.0
Browse files Browse the repository at this point in the history
Actually emit deprecation warnings when using inputtransformer which is
deprecated.
  • Loading branch information
Carreau committed Dec 10, 2024
1 parent 39c7d0e commit 8c051e6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
37 changes: 35 additions & 2 deletions IPython/core/inputtransformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import functools
import re
import tokenize
import warnings
from tokenize import untokenize, TokenError
from io import StringIO

Expand Down Expand Up @@ -42,7 +43,16 @@

class InputTransformer(metaclass=abc.ABCMeta):
"""Abstract base class for line-based input transformers."""


def __init__(self):
warnings.warn(
"`InputTransformer` has been deprecated since IPython 7.0"
" and emit a warnig since IPython 8.31, it"
" will be removed in the future",
DeprecationWarning,
stacklevel=2,
)

@abc.abstractmethod
def push(self, line):
"""Send a line of input to the transformer, returning the transformed
Expand Down Expand Up @@ -78,6 +88,14 @@ def transformer_factory(**kwargs):
class StatelessInputTransformer(InputTransformer):
"""Wrapper for a stateless input transformer implemented as a function."""
def __init__(self, func):
super().__init__()
warnings.warn(
"`StatelessInputTransformer` has been deprecated since IPython 7.0"
" and emit a warnig since IPython 8.31, it"
" will be removed in the future",
DeprecationWarning,
stacklevel=2,
)
self.func = func

def __repr__(self):
Expand All @@ -96,6 +114,14 @@ class CoroutineInputTransformer(InputTransformer):
"""Wrapper for an input transformer implemented as a coroutine."""
def __init__(self, coro, **kwargs):
# Prime it
super().__init__()
warnings.warn(
"`CoroutineInputTransformer` has been deprecated since IPython 7.0"
" and emit a warnig since IPython 8.31, it"
" will be removed in the future",
DeprecationWarning,
stacklevel=2,
)
self.coro = coro(**kwargs)
next(self.coro)

Expand All @@ -122,6 +148,13 @@ class TokenInputTransformer(InputTransformer):
return an iterable which can be passed to tokenize.untokenize().
"""
def __init__(self, func):
warnings.warn(
"`CoroutineInputTransformer` has been deprecated since IPython 7.0"
" and emit a warnig since IPython 8.31, it"
" will be removed in the future",
DeprecationWarning,
stacklevel=2,
)
self.func = func
self.buf = []
self.reset_tokenizer()
Expand Down Expand Up @@ -167,7 +200,7 @@ def reset(self):

class assemble_python_lines(TokenInputTransformer):
def __init__(self):
super(assemble_python_lines, self).__init__(None)
super().__init__(None)

def output(self, tokens):
return self.reset()
Expand Down
6 changes: 0 additions & 6 deletions IPython/core/tests/test_inputsplitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,12 +320,6 @@ def test_unicode(self):
self.isp.push(u'\xc3\xa9')
self.isp.push(u"u'\xc3\xa9'")

@pytest.mark.xfail(
reason="Bug in python 3.9.8 – bpo 45738",
condition=sys.version_info in [(3, 11, 0, "alpha", 2)],
raises=SystemError,
strict=True,
)
def test_line_continuation(self):
""" Test issue #2108."""
isp = self.isp
Expand Down

0 comments on commit 8c051e6

Please sign in to comment.