https://github.com/python/cpython/commit/9751e1d7df5f1ed0e1520cd24b16750b173c2fbf
commit: 9751e1d7df5f1ed0e1520cd24b16750b173c2fbf
branch: main
author: Serhiy Storchaka <[email protected]>
committer: serhiy-storchaka <[email protected]>
date: 2026-06-29T14:11:03Z
summary:

gh-152587: Make name and value required in tkinter variable methods (GH-152595)

The name parameter of Misc.wait_variable(), setvar() and getvar() and the
value parameter of setvar() no longer have default values, which were not
meaningful ('PY_VAR' and '1').

Co-authored-by: Claude Opus 4.8 <[email protected]>

files:
A Misc/NEWS.d/next/Library/2026-06-29-12-50-28.gh-issue-152587.Lq8wVn.rst
M Doc/whatsnew/3.16.rst
M Lib/test/test_tkinter/test_misc.py
M Lib/tkinter/__init__.py

diff --git a/Doc/whatsnew/3.16.rst b/Doc/whatsnew/3.16.rst
index cde44221e05749..8407d0df325619 100644
--- a/Doc/whatsnew/3.16.rst
+++ b/Doc/whatsnew/3.16.rst
@@ -559,6 +559,14 @@ Porting to Python 3.16
 This section lists previously described changes and other bugfixes
 that may require changes to your code.
 
+* In :mod:`tkinter`, the *name* parameter of the
+  :meth:`~tkinter.Misc.wait_variable`, :meth:`~tkinter.Misc.setvar` and
+  :meth:`~tkinter.Misc.getvar` methods and the *value* parameter of
+  :meth:`!setvar` are now required.  Calling these methods without
+  them, which formerly defaulted to ``'PY_VAR'`` and ``'1'``, now raises
+  :exc:`TypeError`.
+  (Contributed by Serhiy Storchaka in :gh:`152587`.)
+
 
 Build changes
 =============
diff --git a/Lib/test/test_tkinter/test_misc.py 
b/Lib/test/test_tkinter/test_misc.py
index a93f5dee349e64..e6221f7089704d 100644
--- a/Lib/test/test_tkinter/test_misc.py
+++ b/Lib/test/test_tkinter/test_misc.py
@@ -367,6 +367,10 @@ def test_getdouble(self):
     def test_getvar(self):
         self.root.setvar('test_var', 'hello')
         self.assertEqual(self.root.getvar('test_var'), 'hello')
+        # The name and value are required (gh-152587).
+        self.assertRaises(TypeError, self.root.getvar)
+        self.assertRaises(TypeError, self.root.setvar)
+        self.assertRaises(TypeError, self.root.setvar, 'test_var')
 
     def test_register(self):
         result = []
@@ -598,6 +602,8 @@ def test_wait_variable(self):
         self.root.after(1, var.set, 'done')
         self.root.wait_variable(var)  # Returns once the variable is set.
         self.assertEqual(var.get(), 'done')
+        # The name is required (gh-152587).
+        self.assertRaises(TypeError, self.root.wait_variable)
 
     def test_wait_window(self):
         top = tkinter.Toplevel(self.root)
diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py
index 0f16757826e23c..83d11a7695ffbe 100644
--- a/Lib/tkinter/__init__.py
+++ b/Lib/tkinter/__init__.py
@@ -818,7 +818,7 @@ def tk_inactive(self, reset=False, *, displayof=0):
         else:
             return self.tk.getint(self.tk.call(args))
 
-    def wait_variable(self, name='PY_VAR'):
+    def wait_variable(self, name):
         """Wait until the variable is modified.
 
         A parameter of type IntVar, StringVar, DoubleVar or
@@ -843,11 +843,11 @@ def wait_visibility(self, window=None):
             window = self
         self.tk.call('tkwait', 'visibility', window._w)
 
-    def setvar(self, name='PY_VAR', value='1'):
+    def setvar(self, name, value):
         """Set Tcl variable NAME to VALUE."""
         self.tk.setvar(name, value)
 
-    def getvar(self, name='PY_VAR'):
+    def getvar(self, name):
         """Return value of Tcl variable NAME."""
         return self.tk.getvar(name)
 
diff --git 
a/Misc/NEWS.d/next/Library/2026-06-29-12-50-28.gh-issue-152587.Lq8wVn.rst 
b/Misc/NEWS.d/next/Library/2026-06-29-12-50-28.gh-issue-152587.Lq8wVn.rst
new file mode 100644
index 00000000000000..e3a9618c6480bc
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2026-06-29-12-50-28.gh-issue-152587.Lq8wVn.rst
@@ -0,0 +1,5 @@
+In :mod:`tkinter`, the *name* parameter of the
+:meth:`~tkinter.Misc.wait_variable`, :meth:`~tkinter.Misc.setvar` and
+:meth:`~tkinter.Misc.getvar` methods and the *value* parameter of
+:meth:`!setvar` are now required.  Their former default values
+(``'PY_VAR'`` and ``'1'``) were not meaningful.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to