]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-152587: Make name and value required in tkinter variable methods (GH-152595)
authorSerhiy Storchaka <storchaka@gmail.com>
Mon, 29 Jun 2026 14:11:03 +0000 (17:11 +0300)
committerGitHub <noreply@github.com>
Mon, 29 Jun 2026 14:11:03 +0000 (14:11 +0000)
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 <noreply@anthropic.com>
Doc/whatsnew/3.16.rst
Lib/test/test_tkinter/test_misc.py
Lib/tkinter/__init__.py
Misc/NEWS.d/next/Library/2026-06-29-12-50-28.gh-issue-152587.Lq8wVn.rst [new file with mode: 0644]

index cde44221e05749a71f8883280879ebd2c5fe93fb..8407d0df3256190b165b6c0d4b41140e318654b3 100644 (file)
@@ -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
 =============
index a93f5dee349e648328e4178453e948552cc78fe0..e6221f7089704d0e0d1d471919b1897ffad1c98c 100644 (file)
@@ -367,6 +367,10 @@ class MiscTest(AbstractTkTest, unittest.TestCase):
     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 @@ class MiscTest(AbstractTkTest, unittest.TestCase):
         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)
index 0f16757826e23c8ef2aae22f56fa5132b1b9a7d7..83d11a7695ffbe3d05eb8fab0f59f93cd378955f 100644 (file)
@@ -818,7 +818,7 @@ class Misc:
         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 @@ class Misc:
             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 (file)
index 0000000..e3a9618
--- /dev/null
@@ -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.