Skip to content
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

Tkinter getint(), getboolean() argument must be str, not tuple #118760

Closed
zooba opened this issue May 8, 2024 · 8 comments
Closed

Tkinter getint(), getboolean() argument must be str, not tuple #118760

zooba opened this issue May 8, 2024 · 8 comments

Comments

@zooba
Copy link
Member

zooba commented May 8, 2024

Bug report

Discovered during 3.13b1 release (we decided not to block the release over it, so this is just a known issue in b1):

While interacting with the config dialog in IDLE, I get these errors printed in the background.

Exception in Tkinter callback
Traceback (most recent call last):
  File "D:\cpython\Lib\tkinter\__init__.py", line 2064, in __call__
    args = self.subst(*args)
  File "D:\cpython\Lib\tkinter\__init__.py", line 1752, in _substitute
    e.state = getint_event(s)
              ~~~~~~~~~~~~^^^
  File "D:\cpython\Lib\tkinter\__init__.py", line 1726, in getint_event
    return getint(s)
TypeError: getint() argument must be str, not tuple

I suspect this is the underlying cause of these test failures, which were discovered in our final stage testing of the Windows release:

======================================================================
ERROR: test_highlight_target_text_mouse (idlelib.idle_test.test_configdialog.HighPageTest.test_highlight_target_text_mouse)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "D:\a\1\b\Python\Lib\idlelib\idle_test\test_configdialog.py", line 447, in test_highlight_target_text_mouse
    eq(d.highlight_target.get(), elem[tag])
                                 ~~~~^^^^^
KeyError: 'sel'

======================================================================
FAIL: test_highlight_sample_b1_motion (idlelib.idle_test.test_configdialog.HighPageTest.test_highlight_sample_b1_motion)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "D:\a\1\b\Python\Lib\idlelib\idle_test\test_configdialog.py", line 493, in test_highlight_sample_b1_motion
    eq(hs.tag_ranges('sel'), ())
    ~~^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: Tuples differ: (<string object: '1.0'>, <string object: '1.24'>) != ()

First tuple contains 2 additional elements.
First extra element 0:
<string object: '1.0'>

- (<string object: '1.0'>, <string object: '1.24'>)
+ ()

======================================================================
FAIL: test_highlight_sample_double_click (idlelib.idle_test.test_configdialog.HighPageTest.test_highlight_sample_double_click)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "D:\a\1\b\Python\Lib\idlelib\idle_test\test_configdialog.py", line 471, in test_highlight_sample_double_click
    eq(hs.tag_ranges('sel'), ())
    ~~^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: Tuples differ: (<string object: '1.0'>, <string object: '1.24'>) != ()

First tuple contains 2 additional elements.
First extra element 0:
<string object: '1.0'>

- (<string object: '1.0'>, <string object: '1.24'>)
+ ()

----------------------------------------------------------------------

Possibly related to @serhiy-storchaka's recent changes?

Linked PRs

@zooba zooba added type-bug An unexpected behavior, bug, or error OS-windows topic-tkinter topic-IDLE labels May 8, 2024
@terryjreedy terryjreedy changed the title Tkinter getint() argument must be str, not tuple Tkinter getint(), getboolean() argument must be str, not tuple May 8, 2024
@serhiy-storchaka
Copy link
Member

Yes, it is my fault.

@terryjreedy
Copy link
Member

I see same test failures and errors in main and 3.13.0b1, not in 3.13.0a6. In main, I see geting error and also:

Exception in Tkinter callback
Traceback (most recent call last):
  File "F:\dev\3x\Lib\tkinter\__init__.py", line 2064, in __call__
    args = self.subst(*args)
  File "F:\dev\3x\Lib\tkinter\__init__.py", line 1758, in _substitute
    try: e.send_event = getboolean(E)
                        ~~~~~~~~~~^^^
TypeError: getboolean() argument must be str, not tuple

The Setting dialog Highlights page is unique in IDLE in having tag binding, which happen to be for left button clicks. Click on an element in the sample and the callback changes the label and background in the buttons above. The bug is that clicks after the first are often ignored, so that multiple clicks are required for one to be registered. At some point, a double click causes the sample box and the dialog to shrink in height by a half inch.

Because not all clicks are ignored, users can managed if they think to keep trying. I expect this will affect other tkinter apps with tag bindings and think this should be blocker for next beta.

serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue May 8, 2024
For unknown reasons some arguments are passed as a 1-tuple containing a
Tcl_Obj with type "string" and value "0" what wantobjects is 2.
@serhiy-storchaka
Copy link
Member

It is a consequence of #98592.

For unknown reasons some arguments are passed as a 1-tuple containing a Tcl_Obj with type "string" and value "0" what wantobjects is 2 (i.e. when they are not forcefully stringified). This happens only on Windows, and not always, running only the selected test is passed. I also tried to write tests for generated events (#118778), but they do not expose such weird behavior (perhaps for the same reason as it is not always reproducible in IDLE tests).

I have two solutions for this. One -- fix the Event creation code where it fails. Two -- simply restore wantobjects = 1 by default (but keep experimental support for wantobjects = 2). I am going to apply both solutions.

@terryjreedy
Copy link
Member

terryjreedy commented May 8, 2024

Opening Settings with Font tab default raises 2 getint errors. But non-default size is correct.

Selecting Highlights and first click always works. First click after successful click always fails with getboolean error. Sometimes (>1/2?) next click also fails, with getboolean. This is the only random behavior I see. If failure, 3rd click seems to work. Selecting another tab and back to Highlights and first click works.

serhiy-storchaka added a commit that referenced this issue May 15, 2024
For unknown reasons some arguments for Tkinter binding can be created
as a 1-tuple containing a Tcl_Obj when wantobjects is 2.
miss-islington pushed a commit to miss-islington/cpython that referenced this issue May 15, 2024
…ythonGH-118782)

For unknown reasons some arguments for Tkinter binding can be created
as a 1-tuple containing a Tcl_Obj when wantobjects is 2.
(cherry picked from commit 5b88d95)

Co-authored-by: Serhiy Storchaka <[email protected]>
@serhiy-storchaka
Copy link
Member

This may be due to the caching of the mutable Tcl_Obj in the Tcl core, so the string "2" may be interpreted differently depending on the interpretation of other strings "2" -- as a string, a number, a "pixel" object, or a list containing any of the listed.

serhiy-storchaka added a commit that referenced this issue May 15, 2024
…H-118782) (GH-119072)

For unknown reasons some arguments for Tkinter binding can be created
as a 1-tuple containing a Tcl_Obj when wantobjects is 2.
(cherry picked from commit 5b88d95)

Co-authored-by: Serhiy Storchaka <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue May 20, 2024
pythonGH-118784)

It was set to 2 in 65f5e58 (pythonGH-98592).
(cherry picked from commit e188527)

Co-authored-by: Serhiy Storchaka <[email protected]>
serhiy-storchaka added a commit that referenced this issue May 20, 2024
… 1 (GH-118784) (GH-119251)

It was set to 2 in 65f5e58 (GH-98592).
(cherry picked from commit e188527)

Co-authored-by: Serhiy Storchaka <[email protected]>
@encukou
Copy link
Member

encukou commented May 21, 2024

Can this be closed now?

@terryjreedy
Copy link
Member

IDLE and test_idle work fine for me now.

@zooba
Copy link
Member Author

zooba commented May 21, 2024

I don't know that I can confirm fully until we do the next release, as the test that failed was the one that tests the installer after it's produced. But we can easily bypass the tests again if they fail next time, so no further need to keep this open IMHO.

@zooba zooba closed this as completed May 21, 2024
estyxx pushed a commit to estyxx/cpython that referenced this issue Jul 17, 2024
…ythonGH-118782)

For unknown reasons some arguments for Tkinter binding can be created
as a 1-tuple containing a Tcl_Obj when wantobjects is 2.
estyxx pushed a commit to estyxx/cpython that referenced this issue Jul 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

4 participants