Skip to content

Commit 97f1ca1

Browse files
[3.8] bpo-31508: Remove support of arguments in tkinter.ttk.Treeview.selection. (GH-3651)
It was deprecated in 3.6.
1 parent 12e7cd8 commit 97f1ca1

File tree

5 files changed

+18
-48
lines changed

5 files changed

+18
-48
lines changed

Doc/library/tkinter.ttk.rst

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,14 +1094,13 @@ ttk.Treeview
10941094
the tree.
10951095

10961096

1097-
.. method:: selection(selop=None, items=None)
1097+
.. method:: selection()
10981098

1099-
If *selop* is not specified, returns selected items. Otherwise, it will
1100-
act according to the following selection methods.
1099+
Returns a tuple of selected items.
11011100

1102-
.. deprecated-removed:: 3.6 3.8
1103-
Using ``selection()`` for changing the selection state is deprecated.
1104-
Use the following selection methods instead.
1101+
.. versionchanged:: 3.8
1102+
``selection()`` no longer takes arguments. For changing the selection
1103+
state use the following selection methods.
11051104

11061105

11071106
.. method:: selection_set(*items)

Doc/whatsnew/3.8.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,11 @@ This section lists previously described changes and other bugfixes
113113
that may require changes to your code.
114114

115115

116+
Changes in the Python API
117+
-------------------------
118+
119+
* The :meth:`~tkinter.ttk.Treeview.selection` method of the
120+
:class:`tkinter.ttk.Treeview` class no longer takes arguments. Using it with
121+
arguments for changing the selection was deprecated in Python 3.6. Use
122+
specialized methods like :meth:`~tkinter.ttk.Treeview.selection_set` for
123+
changing the selection. (Contributed by Serhiy Storchaka in :issue:`31508`.)

Lib/tkinter/test/test_ttk/test_widgets.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,27 +1556,6 @@ def test_selection(self):
15561556
self.tv.selection_toggle((c1, c3))
15571557
self.assertEqual(self.tv.selection(), (c3, item2))
15581558

1559-
if sys.version_info >= (3, 8):
1560-
import warnings
1561-
warnings.warn(
1562-
'Deprecated API of Treeview.selection() should be removed')
1563-
self.tv.selection_set()
1564-
self.assertEqual(self.tv.selection(), ())
1565-
with self.assertWarns(DeprecationWarning):
1566-
self.tv.selection('set', (c1, item2))
1567-
self.assertEqual(self.tv.selection(), (c1, item2))
1568-
with self.assertWarns(DeprecationWarning):
1569-
self.tv.selection('add', (c1, item1))
1570-
self.assertEqual(self.tv.selection(), (item1, c1, item2))
1571-
with self.assertWarns(DeprecationWarning):
1572-
self.tv.selection('remove', (item1, c3))
1573-
self.assertEqual(self.tv.selection(), (c1, item2))
1574-
with self.assertWarns(DeprecationWarning):
1575-
self.tv.selection('toggle', (c1, c3))
1576-
self.assertEqual(self.tv.selection(), (c3, item2))
1577-
with self.assertWarns(DeprecationWarning):
1578-
selection = self.tv.selection(None)
1579-
self.assertEqual(selection, (c3, item2))
15801559

15811560
def test_set(self):
15821561
self.tv['columns'] = ['A', 'B']

Lib/tkinter/ttk.py

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
import tkinter
2929
from tkinter import _flatten, _join, _stringify, _splitdict
3030

31-
_sentinel = object()
32-
3331
# Verify if Tk is new enough to not need the Tile package
3432
_REQUIRE_TILE = True if tkinter.TkVersion < 8.5 else False
3533

@@ -1396,26 +1394,9 @@ def see(self, item):
13961394
self.tk.call(self._w, "see", item)
13971395

13981396

1399-
def selection(self, selop=_sentinel, items=None):
1397+
def selection(self):
14001398
"""Returns the tuple of selected items."""
1401-
if selop is _sentinel:
1402-
selop = None
1403-
elif selop is None:
1404-
import warnings
1405-
warnings.warn(
1406-
"The selop=None argument of selection() is deprecated "
1407-
"and will be removed in Python 3.8",
1408-
DeprecationWarning, 3)
1409-
elif selop in ('set', 'add', 'remove', 'toggle'):
1410-
import warnings
1411-
warnings.warn(
1412-
"The selop argument of selection() is deprecated "
1413-
"and will be removed in Python 3.8, "
1414-
"use selection_%s() instead" % (selop,),
1415-
DeprecationWarning, 3)
1416-
else:
1417-
raise TypeError('Unsupported operation')
1418-
return self.tk.splitlist(self.tk.call(self._w, "selection", selop, items))
1399+
return self.tk.splitlist(self.tk.call(self._w, "selection"))
14191400

14201401

14211402
def _selection(self, selop, items):
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Removed support of arguments in `tkinter.ttk.Treeview.selection`. It was
2+
deprecated in 3.6. Use specialized methods like `selection_set` for
3+
changing the selection.

0 commit comments

Comments
 (0)