-
-
Couldn't load subscription status.
- Fork 33.2k
gh-120220: Deprecate legacy methods for tracing variables in Tkinter #120223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
cd263e2
5a75e86
0917d8b
4df88b7
5dd8f3a
3cba3b7
887f01c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -498,10 +498,14 @@ def trace_variable(self, mode, callback): | |
|
|
||
| Return the name of the callback. | ||
|
|
||
| This deprecated method wraps a deprecated Tcl method that will | ||
| likely be removed in the future. Use trace_add() instead. | ||
| This deprecated method wraps a deprecated Tcl method removed | ||
| in Tcl 9.0. Use trace_add() instead. | ||
| """ | ||
| # TODO: Add deprecation warning | ||
| import warnings | ||
| warnings.warn( | ||
| "trace_variable() is deprecated and not supported with Tcl 9, " | ||
| "use trace_add() instead", | ||
| DeprecationWarning, stacklevel=2) | ||
| cbname = self._register(callback) | ||
| self._tk.call("trace", "variable", self._name, mode, cbname) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this line be wrapped in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And what to do after catching the exception? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Raise a better error message -- IF the TclError message is unclear, such as not specifying that failure us 9.0 specific. I don't have 9.0 installed to test this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The error message is " There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was thinking about the case when people have DeprecationWarnings turned off. A possibility would be, when running tk9+, to immediately raise an error with more direct message 'This method does not exist in tk9, use...' right in trace_xyz itself. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you suggest to write something like this? try:
self._tk.call("trace", "variable", self._name, mode, cbname)
except _tkinter.TclError as err:
if str(err) == 'bad option "variable": must be add, info, or remove':
raise TypeError('trace_variable() is not supported '
'with Tcl 9; use trace_add() instead')
raiseThis is too verbose and fragile. If they change the error message it will not work. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps this could use an exception note, that way it won't change the type. Just needs the message to be clear another error may have occurred. |
||
| return cbname | ||
|
|
@@ -514,10 +518,14 @@ def trace_vdelete(self, mode, cbname): | |
| MODE is one of "r", "w", "u" for read, write, undefine. | ||
| CBNAME is the name of the callback returned from trace_variable or trace. | ||
|
|
||
| This deprecated method wraps a deprecated Tcl method that will | ||
| likely be removed in the future. Use trace_remove() instead. | ||
| This deprecated method wraps a deprecated Tcl method removed | ||
| in Tcl 9.0. Use trace_remove() instead. | ||
| """ | ||
| # TODO: Add deprecation warning | ||
| import warnings | ||
| warnings.warn( | ||
| "trace_vdelete() is deprecated and not supported with Tcl 9, " | ||
| "use trace_remove() instead", | ||
| DeprecationWarning, stacklevel=2) | ||
| self._tk.call("trace", "vdelete", self._name, mode, cbname) | ||
| cbname = self._tk.splitlist(cbname)[0] | ||
| for m, ca in self.trace_info(): | ||
|
|
@@ -533,10 +541,14 @@ def trace_vdelete(self, mode, cbname): | |
| def trace_vinfo(self): | ||
| """Return all trace callback information. | ||
|
|
||
| This deprecated method wraps a deprecated Tcl method that will | ||
| likely be removed in the future. Use trace_info() instead. | ||
| This deprecated method wraps a deprecated Tcl method removed | ||
| in Tcl 9.0. Use trace_info() instead. | ||
| """ | ||
| # TODO: Add deprecation warning | ||
| import warnings | ||
| warnings.warn( | ||
| "trace_vinfo() is deprecated and not supported with Tcl 9, " | ||
| "use trace_info() instead", | ||
| DeprecationWarning, stacklevel=2) | ||
| return [self._tk.splitlist(x) for x in self._tk.splitlist( | ||
| self._tk.call("trace", "vinfo", self._name))] | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Deprecate the :class:`!tkinter.Variable` methods :meth:`!trace_variable`, | ||
| :meth:`!trace_vdelete` and :meth:`!trace_vinfo`. Methods :meth:`!trace_add`, | ||
| :meth:`!trace_remove` and :meth:`!trace_info` can be used instead. |
Uh oh!
There was an error while loading. Please reload this page.