Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f0a8f9d

Browse files
authored
remove a number of pending Deprecations (#14653)
2 parents 4bea4f5 + 8131ff8 commit f0a8f9d

2 files changed

Lines changed: 0 additions & 317 deletions

File tree

IPython/utils/tests/test_text.py

Lines changed: 0 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -27,137 +27,6 @@
2727
#-----------------------------------------------------------------------------
2828

2929

30-
@pytest.mark.parametrize(
31-
"expected, width, row_first, spread",
32-
(
33-
(
34-
"aaaaa bbbbb ccccc ddddd\n",
35-
80,
36-
False,
37-
False,
38-
),
39-
(
40-
"aaaaa ccccc\nbbbbb ddddd\n",
41-
25,
42-
False,
43-
False,
44-
),
45-
(
46-
"aaaaa ccccc\nbbbbb ddddd\n",
47-
12,
48-
False,
49-
False,
50-
),
51-
(
52-
"aaaaa\nbbbbb\nccccc\nddddd\n",
53-
10,
54-
False,
55-
False,
56-
),
57-
(
58-
"aaaaa bbbbb ccccc ddddd\n",
59-
80,
60-
True,
61-
False,
62-
),
63-
(
64-
"aaaaa bbbbb\nccccc ddddd\n",
65-
25,
66-
True,
67-
False,
68-
),
69-
(
70-
"aaaaa bbbbb\nccccc ddddd\n",
71-
12,
72-
True,
73-
False,
74-
),
75-
(
76-
"aaaaa\nbbbbb\nccccc\nddddd\n",
77-
10,
78-
True,
79-
False,
80-
),
81-
(
82-
"aaaaa bbbbb ccccc ddddd\n",
83-
40,
84-
False,
85-
True,
86-
),
87-
(
88-
"aaaaa ccccc\nbbbbb ddddd\n",
89-
20,
90-
False,
91-
True,
92-
),
93-
(
94-
"aaaaa ccccc\nbbbbb ddddd\n",
95-
12,
96-
False,
97-
True,
98-
),
99-
(
100-
"aaaaa\nbbbbb\nccccc\nddddd\n",
101-
10,
102-
False,
103-
True,
104-
),
105-
),
106-
)
107-
def test_columnize(expected, width, row_first, spread):
108-
"""Basic columnize tests."""
109-
size = 5
110-
items = [l*size for l in 'abcd']
111-
with pytest.warns(PendingDeprecationWarning):
112-
out = text.columnize(
113-
items, displaywidth=width, row_first=row_first, spread=spread
114-
)
115-
assert out == expected
116-
117-
118-
def test_columnize_random():
119-
"""Test with random input to hopefully catch edge case """
120-
for row_first in [True, False]:
121-
for nitems in [random.randint(2,70) for i in range(2,20)]:
122-
displaywidth = random.randint(20,200)
123-
rand_len = [random.randint(2,displaywidth) for i in range(nitems)]
124-
items = ['x'*l for l in rand_len]
125-
with pytest.warns(PendingDeprecationWarning):
126-
out = text.columnize(
127-
items, row_first=row_first, displaywidth=displaywidth
128-
)
129-
longer_line = max([len(x) for x in out.split("\n")])
130-
longer_element = max(rand_len)
131-
assert longer_line <= displaywidth, (
132-
f"Columnize displayed something lager than displaywidth : {longer_line}\n"
133-
f"longer element : {longer_element}\n"
134-
f"displaywidth : {displaywidth}\n"
135-
f"number of element : {nitems}\n"
136-
f"size of each element : {rand_len}\n"
137-
f"row_first={row_first}\n"
138-
)
139-
140-
141-
@pytest.mark.parametrize("row_first", [True, False])
142-
def test_columnize_medium(row_first):
143-
"""Test with inputs than shouldn't be wider than 80"""
144-
size = 40
145-
items = [l*size for l in 'abc']
146-
with pytest.warns(PendingDeprecationWarning):
147-
out = text.columnize(items, row_first=row_first, displaywidth=80)
148-
assert out == "\n".join(items + [""]), "row_first={0}".format(row_first)
149-
150-
151-
@pytest.mark.parametrize("row_first", [True, False])
152-
def test_columnize_long(row_first):
153-
"""Test columnize with inputs longer than the display window"""
154-
size = 11
155-
items = [l*size for l in 'abc']
156-
with pytest.warns(PendingDeprecationWarning):
157-
out = text.columnize(items, row_first=row_first, displaywidth=size - 1)
158-
assert out == "\n".join(items + [""]), "row_first={0}".format(row_first)
159-
160-
16130
def eval_formatter_check(f):
16231
ns = dict(n=12, pi=math.pi, stuff='hello there', os=os, u=u"café", b="café")
16332
s = f.format("{n} {n//4} {stuff.split()[0]}", **ns)

IPython/utils/text.py

Lines changed: 0 additions & 186 deletions
Original file line numberDiff line numberDiff line change
@@ -363,25 +363,6 @@ def marquee(txt: str = "", width: int = 78, mark: str = "*") -> str:
363363
return '%s %s %s' % (marks,txt,marks)
364364

365365

366-
ini_spaces_re = re.compile(r'^(\s+)')
367-
368-
369-
def num_ini_spaces(strng: str) -> int:
370-
"""Return the number of initial spaces in a string"""
371-
warnings.warn(
372-
"`num_ini_spaces` is Pending Deprecation since IPython 8.17."
373-
"It is considered for removal in in future version. "
374-
"Please open an issue if you believe it should be kept.",
375-
stacklevel=2,
376-
category=PendingDeprecationWarning,
377-
)
378-
ini_spaces = ini_spaces_re.match(strng)
379-
if ini_spaces:
380-
return ini_spaces.end()
381-
else:
382-
return 0
383-
384-
385366
def format_screen(strng: str) -> str:
386367
"""Format a string for screen printing.
387368
@@ -501,26 +482,6 @@ def strip_email_quotes(text: str) -> str:
501482
return text
502483

503484

504-
def strip_ansi(source: str) -> str:
505-
"""
506-
Remove ansi escape codes from text.
507-
508-
Parameters
509-
----------
510-
source : str
511-
Source to remove the ansi from
512-
"""
513-
warnings.warn(
514-
"`strip_ansi` is Pending Deprecation since IPython 8.17."
515-
"It is considered for removal in in future version. "
516-
"Please open an issue if you believe it should be kept.",
517-
stacklevel=2,
518-
category=PendingDeprecationWarning,
519-
)
520-
521-
return re.sub(r'\033\[(\d|;)+?m', '', source)
522-
523-
524485
class EvalFormatter(Formatter):
525486
"""A String Formatter that allows evaluation of simple expressions.
526487
@@ -704,153 +665,6 @@ def _get_or_default(mylist: List[T], i: int, default: T) -> T:
704665
return mylist[i]
705666

706667

707-
def compute_item_matrix(
708-
items: List[str],
709-
row_first: bool = False,
710-
empty: Optional[str] = None,
711-
*,
712-
separator_size: int = 2,
713-
displaywidth: int = 80,
714-
) -> Tuple[List[List[int]], Dict[str, int]]:
715-
"""Returns a nested list, and info to columnize items
716-
717-
Parameters
718-
----------
719-
items
720-
list of strings to columize
721-
row_first : (default False)
722-
Whether to compute columns for a row-first matrix instead of
723-
column-first (default).
724-
empty : (default None)
725-
default value to fill list if needed
726-
separator_size : int (default=2)
727-
How much characters will be used as a separation between each columns.
728-
displaywidth : int (default=80)
729-
The width of the area onto which the columns should enter
730-
731-
Returns
732-
-------
733-
strings_matrix
734-
nested list of string, the outer most list contains as many list as
735-
rows, the innermost lists have each as many element as columns. If the
736-
total number of elements in `items` does not equal the product of
737-
rows*columns, the last element of some lists are filled with `None`.
738-
dict_info
739-
some info to make columnize easier:
740-
741-
num_columns
742-
number of columns
743-
max_rows
744-
maximum number of rows (final number may be less)
745-
column_widths
746-
list of with of each columns
747-
optimal_separator_width
748-
best separator width between columns
749-
750-
Examples
751-
--------
752-
::
753-
754-
In [1]: l = ['aaa','b','cc','d','eeeee','f','g','h','i','j','k','l']
755-
In [2]: list, info = compute_item_matrix(l, displaywidth=12)
756-
In [3]: list
757-
Out[3]: [['aaa', 'f', 'k'], ['b', 'g', 'l'], ['cc', 'h', None], ['d', 'i', None], ['eeeee', 'j', None]]
758-
In [4]: ideal = {'num_columns': 3, 'column_widths': [5, 1, 1], 'optimal_separator_width': 2, 'max_rows': 5}
759-
In [5]: all((info[k] == ideal[k] for k in ideal.keys()))
760-
Out[5]: True
761-
"""
762-
warnings.warn(
763-
"`compute_item_matrix` is Pending Deprecation since IPython 8.17."
764-
"It is considered for removal in in future version. "
765-
"Please open an issue if you believe it should be kept.",
766-
stacklevel=2,
767-
category=PendingDeprecationWarning,
768-
)
769-
info = _find_optimal(
770-
list(map(len, items)), # type: ignore[arg-type]
771-
row_first,
772-
separator_size=separator_size,
773-
displaywidth=displaywidth,
774-
)
775-
nrow, ncol = info["max_rows"], info["num_columns"]
776-
if row_first:
777-
return (
778-
[
779-
[
780-
_get_or_default(
781-
items, r * ncol + c, default=empty
782-
) # type:ignore[misc]
783-
for c in range(ncol)
784-
]
785-
for r in range(nrow)
786-
],
787-
info,
788-
)
789-
else:
790-
return (
791-
[
792-
[
793-
_get_or_default(
794-
items, c * nrow + r, default=empty
795-
) # type:ignore[misc]
796-
for c in range(ncol)
797-
]
798-
for r in range(nrow)
799-
],
800-
info,
801-
)
802-
803-
804-
def columnize(
805-
items: List[str],
806-
row_first: bool = False,
807-
separator: str = " ",
808-
displaywidth: int = 80,
809-
spread: bool = False,
810-
) -> str:
811-
"""Transform a list of strings into a single string with columns.
812-
813-
Parameters
814-
----------
815-
items : sequence of strings
816-
The strings to process.
817-
row_first : (default False)
818-
Whether to compute columns for a row-first matrix instead of
819-
column-first (default).
820-
separator : str, optional [default is two spaces]
821-
The string that separates columns.
822-
displaywidth : int, optional [default is 80]
823-
Width of the display in number of characters.
824-
825-
Returns
826-
-------
827-
The formatted string.
828-
"""
829-
warnings.warn(
830-
"`columnize` is Pending Deprecation since IPython 8.17."
831-
"It is considered for removal in future versions. "
832-
"Please open an issue if you believe it should be kept.",
833-
stacklevel=2,
834-
category=PendingDeprecationWarning,
835-
)
836-
if not items:
837-
return "\n"
838-
matrix: List[List[int]]
839-
matrix, info = compute_item_matrix(
840-
items,
841-
row_first=row_first,
842-
separator_size=len(separator),
843-
displaywidth=displaywidth,
844-
)
845-
if spread:
846-
separator = separator.ljust(int(info["optimal_separator_width"]))
847-
fmatrix: List[filter[int]] = [filter(None, x) for x in matrix]
848-
sjoin = lambda x: separator.join(
849-
[y.ljust(w, " ") for y, w in zip(x, cast(List[int], info["column_widths"]))]
850-
)
851-
return "\n".join(map(sjoin, fmatrix)) + "\n"
852-
853-
854668
def get_text_list(
855669
list_: List[str], last_sep: str = " and ", sep: str = ", ", wrap_item_with: str = ""
856670
) -> str:

0 commit comments

Comments
 (0)