Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c46635a

Browse filesBrowse files
gh-120220: Deprecate legacy methods for tracing variables in Tkinter (GH-120223)
They do not work with Tcl 9.0. Use new methods added in Python 3.6.
1 parent 814ca11 commit c46635a
Copy full SHA for c46635a

File tree

Expand file treeCollapse file tree

4 files changed

+58
-21
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+58
-21
lines changed

‎Doc/whatsnew/3.14.rst

Copy file name to clipboardExpand all lines: Doc/whatsnew/3.14.rst
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1642,6 +1642,13 @@ Deprecated
16421642
Deprecate :meth:`symtable.Class.get_methods` due to the lack of interest.
16431643
(Contributed by Bénédikt Tran in :gh:`119698`.)
16441644

1645+
* :mod:`tkinter`:
1646+
The :class:`!tkinter.Variable` methods :meth:`!trace_variable`,
1647+
:meth:`!trace_vdelete` and :meth:`!trace_vinfo` are now deprecated.
1648+
Use :meth:`!trace_add`, :meth:`!trace_remove` and :meth:`!trace_info`
1649+
instead.
1650+
(Contributed by Serhiy Storchaka in :gh:`120220`.)
1651+
16451652
* :mod:`urllib.parse`:
16461653
Accepting objects with false values (like ``0`` and ``[]``) except empty
16471654
strings, byte-like objects and ``None`` in :mod:`urllib.parse` functions

‎Lib/test/test_tkinter/test_variables.py

Copy file name to clipboardExpand all lines: Lib/test/test_tkinter/test_variables.py
+27-12Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,14 @@ def read_tracer(*args):
122122
trace.append(('read',) + args)
123123
def write_tracer(*args):
124124
trace.append(('write',) + args)
125-
cb1 = v.trace_variable('r', read_tracer)
126-
cb2 = v.trace_variable('wu', write_tracer)
127-
self.assertEqual(sorted(v.trace_vinfo()), [('r', cb1), ('wu', cb2)])
125+
with self.assertWarns(DeprecationWarning) as cm:
126+
cb1 = v.trace_variable('r', read_tracer)
127+
self.assertEqual(cm.filename, __file__)
128+
with self.assertWarns(DeprecationWarning):
129+
cb2 = v.trace_variable('wu', write_tracer)
130+
with self.assertWarns(DeprecationWarning) as cm:
131+
self.assertEqual(sorted(v.trace_vinfo()), [('r', cb1), ('wu', cb2)])
132+
self.assertEqual(cm.filename, __file__)
128133
self.assertEqual(trace, [])
129134

130135
v.set('spam')
@@ -135,20 +140,30 @@ def write_tracer(*args):
135140
self.assertEqual(trace, [('read', vname, '', 'r')])
136141

137142
trace = []
138-
info = sorted(v.trace_vinfo())
139-
v.trace_vdelete('w', cb1) # Wrong mode
140-
self.assertEqual(sorted(v.trace_vinfo()), info)
143+
with self.assertWarns(DeprecationWarning):
144+
info = sorted(v.trace_vinfo())
145+
with self.assertWarns(DeprecationWarning):
146+
v.trace_vdelete('w', cb1) # Wrong mode
147+
with self.assertWarns(DeprecationWarning):
148+
self.assertEqual(sorted(v.trace_vinfo()), info)
141149
with self.assertRaises(TclError):
142-
v.trace_vdelete('r', 'spam') # Wrong command name
143-
self.assertEqual(sorted(v.trace_vinfo()), info)
144-
v.trace_vdelete('r', (cb1, 43)) # Wrong arguments
145-
self.assertEqual(sorted(v.trace_vinfo()), info)
150+
with self.assertWarns(DeprecationWarning):
151+
v.trace_vdelete('r', 'spam') # Wrong command name
152+
with self.assertWarns(DeprecationWarning):
153+
self.assertEqual(sorted(v.trace_vinfo()), info)
154+
with self.assertWarns(DeprecationWarning):
155+
v.trace_vdelete('r', (cb1, 43)) # Wrong arguments
156+
with self.assertWarns(DeprecationWarning):
157+
self.assertEqual(sorted(v.trace_vinfo()), info)
146158
v.get()
147159
self.assertEqual(trace, [('read', vname, '', 'r')])
148160

149161
trace = []
150-
v.trace_vdelete('r', cb1)
151-
self.assertEqual(v.trace_vinfo(), [('wu', cb2)])
162+
with self.assertWarns(DeprecationWarning) as cm:
163+
v.trace_vdelete('r', cb1)
164+
self.assertEqual(cm.filename, __file__)
165+
with self.assertWarns(DeprecationWarning):
166+
self.assertEqual(v.trace_vinfo(), [('wu', cb2)])
152167
v.get()
153168
self.assertEqual(trace, [])
154169

‎Lib/tkinter/__init__.py

Copy file name to clipboardExpand all lines: Lib/tkinter/__init__.py
+21-9Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -500,10 +500,14 @@ def trace_variable(self, mode, callback):
500500
501501
Return the name of the callback.
502502
503-
This deprecated method wraps a deprecated Tcl method that will
504-
likely be removed in the future. Use trace_add() instead.
503+
This deprecated method wraps a deprecated Tcl method removed
504+
in Tcl 9.0. Use trace_add() instead.
505505
"""
506-
# TODO: Add deprecation warning
506+
import warnings
507+
warnings.warn(
508+
"trace_variable() is deprecated and not supported with Tcl 9; "
509+
"use trace_add() instead.",
510+
DeprecationWarning, stacklevel=2)
507511
cbname = self._register(callback)
508512
self._tk.call("trace", "variable", self._name, mode, cbname)
509513
return cbname
@@ -516,10 +520,14 @@ def trace_vdelete(self, mode, cbname):
516520
MODE is one of "r", "w", "u" for read, write, undefine.
517521
CBNAME is the name of the callback returned from trace_variable or trace.
518522
519-
This deprecated method wraps a deprecated Tcl method that will
520-
likely be removed in the future. Use trace_remove() instead.
523+
This deprecated method wraps a deprecated Tcl method removed
524+
in Tcl 9.0. Use trace_remove() instead.
521525
"""
522-
# TODO: Add deprecation warning
526+
import warnings
527+
warnings.warn(
528+
"trace_vdelete() is deprecated and not supported with Tcl 9; "
529+
"use trace_remove() instead.",
530+
DeprecationWarning, stacklevel=2)
523531
self._tk.call("trace", "vdelete", self._name, mode, cbname)
524532
cbname = self._tk.splitlist(cbname)[0]
525533
for m, ca in self.trace_info():
@@ -535,10 +543,14 @@ def trace_vdelete(self, mode, cbname):
535543
def trace_vinfo(self):
536544
"""Return all trace callback information.
537545
538-
This deprecated method wraps a deprecated Tcl method that will
539-
likely be removed in the future. Use trace_info() instead.
546+
This deprecated method wraps a deprecated Tcl method removed
547+
in Tcl 9.0. Use trace_info() instead.
540548
"""
541-
# TODO: Add deprecation warning
549+
import warnings
550+
warnings.warn(
551+
"trace_vinfo() is deprecated and not supported with Tcl 9; "
552+
"use trace_info() instead.",
553+
DeprecationWarning, stacklevel=2)
542554
return [self._tk.splitlist(x) for x in self._tk.splitlist(
543555
self._tk.call("trace", "vinfo", self._name))]
544556

+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Deprecate the :class:`!tkinter.Variable` methods :meth:`!trace_variable`,
2+
:meth:`!trace_vdelete` and :meth:`!trace_vinfo`. Methods :meth:`!trace_add`,
3+
:meth:`!trace_remove` and :meth:`!trace_info` can be used instead.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.