From 028f9b394d6938a9b3c9f443017c13fb2101ce18 2024-12-10 14:16:26 From: M Bussonnier Date: 2024-12-10 14:16:26 Subject: [PATCH] Backport PR #14601: Deprecate inputtransformer since 7.0 --- diff --git a/IPython/core/inputtransformer.py b/IPython/core/inputtransformer.py index bb1061e..5229be4 100644 --- a/IPython/core/inputtransformer.py +++ b/IPython/core/inputtransformer.py @@ -9,6 +9,7 @@ import abc import functools import re import tokenize +import warnings from tokenize import untokenize, TokenError from io import StringIO @@ -42,7 +43,16 @@ ESC_SEQUENCES = [ESC_SHELL, ESC_SH_CAP, ESC_HELP ,\ 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 @@ -78,6 +88,14 @@ class InputTransformer(metaclass=abc.ABCMeta): 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): @@ -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) @@ -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() @@ -167,7 +200,7 @@ class TokenInputTransformer(InputTransformer): 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() diff --git a/docs/source/config/inputtransforms.rst b/docs/source/config/inputtransforms.rst index 33f1488..222d113 100644 --- a/docs/source/config/inputtransforms.rst +++ b/docs/source/config/inputtransforms.rst @@ -13,7 +13,7 @@ interactive interface. Using them carelessly can easily break IPython! String based transformations ============================ -.. currentmodule:: IPython.core.inputtransforms +.. currentmodule:: IPython.core.inputtransformers2 When the user enters code, it is first processed as a string. By the end of this stage, it must be valid Python syntax.