Skip to content

Commit c696eef

Browse files
authored
Backport PR ipython#14601 on branch 8.x (Deprecate inputtransformer since 7.0) (ipython#14603)
Backport PR ipython#14601: Deprecate inputtransformer since 7.0
2 parents 86a74d8 + 028f9b3 commit c696eef

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

IPython/core/inputtransformer.py

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import functools
1010
import re
1111
import tokenize
12+
import warnings
1213
from tokenize import untokenize, TokenError
1314
from io import StringIO
1415

@@ -42,7 +43,16 @@
4243

4344
class InputTransformer(metaclass=abc.ABCMeta):
4445
"""Abstract base class for line-based input transformers."""
45-
46+
47+
def __init__(self):
48+
warnings.warn(
49+
"`InputTransformer` has been deprecated since IPython 7.0"
50+
" and emit a warnig since IPython 8.31, it"
51+
" will be removed in the future",
52+
DeprecationWarning,
53+
stacklevel=2,
54+
)
55+
4656
@abc.abstractmethod
4757
def push(self, line):
4858
"""Send a line of input to the transformer, returning the transformed
@@ -78,6 +88,14 @@ def transformer_factory(**kwargs):
7888
class StatelessInputTransformer(InputTransformer):
7989
"""Wrapper for a stateless input transformer implemented as a function."""
8090
def __init__(self, func):
91+
super().__init__()
92+
warnings.warn(
93+
"`StatelessInputTransformer` has been deprecated since IPython 7.0"
94+
" and emit a warnig since IPython 8.31, it"
95+
" will be removed in the future",
96+
DeprecationWarning,
97+
stacklevel=2,
98+
)
8199
self.func = func
82100

83101
def __repr__(self):
@@ -96,6 +114,14 @@ class CoroutineInputTransformer(InputTransformer):
96114
"""Wrapper for an input transformer implemented as a coroutine."""
97115
def __init__(self, coro, **kwargs):
98116
# Prime it
117+
super().__init__()
118+
warnings.warn(
119+
"`CoroutineInputTransformer` has been deprecated since IPython 7.0"
120+
" and emit a warnig since IPython 8.31, it"
121+
" will be removed in the future",
122+
DeprecationWarning,
123+
stacklevel=2,
124+
)
99125
self.coro = coro(**kwargs)
100126
next(self.coro)
101127

@@ -122,6 +148,13 @@ class TokenInputTransformer(InputTransformer):
122148
return an iterable which can be passed to tokenize.untokenize().
123149
"""
124150
def __init__(self, func):
151+
warnings.warn(
152+
"`CoroutineInputTransformer` has been deprecated since IPython 7.0"
153+
" and emit a warnig since IPython 8.31, it"
154+
" will be removed in the future",
155+
DeprecationWarning,
156+
stacklevel=2,
157+
)
125158
self.func = func
126159
self.buf = []
127160
self.reset_tokenizer()
@@ -167,7 +200,7 @@ def reset(self):
167200

168201
class assemble_python_lines(TokenInputTransformer):
169202
def __init__(self):
170-
super(assemble_python_lines, self).__init__(None)
203+
super().__init__(None)
171204

172205
def output(self, tokens):
173206
return self.reset()

docs/source/config/inputtransforms.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ interactive interface. Using them carelessly can easily break IPython!
1313
String based transformations
1414
============================
1515

16-
.. currentmodule:: IPython.core.inputtransforms
16+
.. currentmodule:: IPython.core.inputtransformers2
1717

1818
When the user enters code, it is first processed as a string. By the
1919
end of this stage, it must be valid Python syntax.

0 commit comments

Comments
 (0)