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

Tk 8.6.0 introduces TypeError. (Tk 8.5.13 works) #61013

Closed
serwy mannequin opened this issue Dec 29, 2012 · 16 comments
Closed

Tk 8.6.0 introduces TypeError. (Tk 8.5.13 works) #61013

serwy mannequin opened this issue Dec 29, 2012 · 16 comments
Assignees
Labels
topic-tkinter type-bug An unexpected behavior, bug, or error

Comments

@serwy
Copy link
Mannequin

serwy mannequin commented Dec 29, 2012

BPO 16809
Nosy @serwy, @vadmium, @serhiy-storchaka, @floppym
Dependencies
  • bpo-18101: Tk.split() doesn't work with nested Unicode strings
  • Files
  • tk_86_error.py
  • tk_86_workaround.py
  • tkinter_no_tcl_obj.patch: Switch off Tcl_Obj
  • tkinter_split.patch: Tk.splitline() and Tk.split() work with Tcl_Obj
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/serhiy-storchaka'
    closed_at = <Date 2013-10-27.10:46:32.859>
    created_at = <Date 2012-12-29.06:38:27.407>
    labels = ['type-bug', 'expert-tkinter']
    title = 'Tk 8.6.0 introduces TypeError. (Tk 8.5.13 works)'
    updated_at = <Date 2013-10-27.10:46:32.857>
    user = 'https://github.com/serwy'

    bugs.python.org fields:

    activity = <Date 2013-10-27.10:46:32.857>
    actor = 'serhiy.storchaka'
    assignee = 'serhiy.storchaka'
    closed = True
    closed_date = <Date 2013-10-27.10:46:32.859>
    closer = 'serhiy.storchaka'
    components = ['Tkinter']
    creation = <Date 2012-12-29.06:38:27.407>
    creator = 'roger.serwy'
    dependencies = ['18101']
    files = ['28476', '30421', '30428', '30429']
    hgrepos = []
    issue_num = 16809
    keywords = ['patch']
    message_count = 16.0
    messages = ['178475', '178720', '178729', '178757', '184624', '184840', '190336', '190360', '190362', '190363', '192062', '193586', '195899', '195901', '195902', '201445']
    nosy_count = 8.0
    nosy_names = ['gpolo', 'roger.serwy', 'Arfrever', 'python-dev', 'martin.panter', 'serhiy.storchaka', 'floppymaster', 'alejandroautalan']
    pr_nums = []
    priority = 'critical'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue16809'
    versions = ['Python 2.7', 'Python 3.3', 'Python 3.4']

    @serwy
    Copy link
    Mannequin Author

    serwy mannequin commented Dec 29, 2012

    I am running Arch Linux with the latest Tcl/Tk 8.6.0 build with Python 2.7.3 and 3.3.0, and the latest 3.4.0a0 build from the repository.

    Running the attached script fails when calling pack_info(). Here's is the script's output:

    8.6
    Traceback (most recent call last):
      File "tk_86_error.py", line 6, in <module>
        label.pack_info()
      File "/usr/lib/python3.3/tkinter/__init__.py", line 1884, in pack_info
        self.tk.call('pack', 'info', self._w))
    TypeError: Can't convert '_tkinter.Tcl_Obj' object to str implicitly

    This error did not occur when using Tk 8.5.13.

    @serwy serwy mannequin added topic-tkinter type-bug An unexpected behavior, bug, or error labels Dec 29, 2012
    @serwy
    Copy link
    Mannequin Author

    serwy mannequin commented Dec 31, 2012

    In Objects/unicodeobject.c in PyUnicode_FromObject, the call to PyUnicode_CheckExact fails when using 8.6.0 but works with 8.5.13.

    @serhiy-storchaka
    Copy link
    Member

    I don't install Tcl/Tk 8.6 yet, but looks as "pack info" call returns a new type of Tcl data (perhaps DictType) which doesn't detected in FromObj().

    @serhiy-storchaka
    Copy link
    Member

    The simplest fix probably is just wrap self.tk.call() with str() (I have not tested it yet). However the problem is more serious (tkinter doesn't support fully even 8.5 and subtle bugs are possible) and I'll spend some more time on its research.

    @serhiy-storchaka serhiy-storchaka self-assigned this Jan 1, 2013
    @serhiy-storchaka
    Copy link
    Member

    Here is a patch which add support of Tcl_Obj to tkinter's splitlist(). This not only fixes some incompatibility with Tk 8.6, but can fix some issues with older Tk versions (see for example bpo-17397).

    @serwy
    Copy link
    Mannequin Author

    serwy mannequin commented Mar 21, 2013

    Serhiy, I applied your patch but I still get the same error.

    From what I have found so far, the FromObj function in Modules/_tkinter.c relies on cached values for different Tcl_ObjType, as given in the TkappObject struct. From the comment:

    /* We cannot include tclInt.h, as this is internal.
       So we cache interesting types here. */
    

    I haven't traced down the exact difference between 8.5 and 8.6 that causes the existing cached types to not match. The correct behavior from 8.5 is a match to "StringType". I've noticed a lot more macros in the 8.6 headers than in 8.5 which may be the culprit.

    @serwy
    Copy link
    Mannequin Author

    serwy mannequin commented May 30, 2013

    The problem I'm encountering is that tk.splitlist() is now being given a Tcl_Obj instead of a "str" type. Since everything is Tcl is a string, explicitly casting a Tcl_Obj to a string seems reasonable. Attached is some proof-of-concept code to work around the issue.

    Serhiy's patch against 3.4 gives this traceback:

    [python@saturn 3.4]$ ./python tk_86_error.py 
    8.6
    Traceback (most recent call last):
      File "tk_86_error.py", line 6, in <module>
        label.pack_info()
      File "/home/python/python/3.4/Lib/tkinter/__init__.py", line 1924, in pack_info
        if value[:1] == '.':
    TypeError: '_tkinter.Tcl_Obj' object is not subscriptable

    @serhiy-storchaka
    Copy link
    Member

    Yes, I considered this option. A sure way to get rid of this and future changes in Tcl types, is get rid of Tcl_Obj at all and always return strings (if it is not a number or list). The drawback of this method is that occurs unnecessary conversion between Tcl and Python types and that information about types is lost. Also it is possible to hamper support for new Tcl types (dict, StateSpec, etc) in future.

    Another way is much more difficult. We need to allow all Tkinter functions to accept Tcl_Obj. Unfortunately this doesn't solve the problem fully because other code might expect a string instead of Tcl_Obj. We don't have enough test coverage to verify that the changes are sufficient. In any case, there are third-party code, which will also have to change to support the new Tcl versions.

    @serhiy-storchaka
    Copy link
    Member

    Here are a patch which quickly switch off Tcl_Obj.

    @serhiy-storchaka
    Copy link
    Member

    And here is a patch which allows Tk.splitline() and Tk.split() to work with Tcl_Obj. It also includes some other minor fixes to support Tcl 8.6. The patch includes a fix for bpo-18101.

    @Arfrever
    Copy link
    Mannequin

    Arfrever mannequin commented Jun 30, 2013

    Please commit the full patch in all active branches.

    @alejandroautalan
    Copy link
    Mannequin

    alejandroautalan mannequin commented Jul 23, 2013

    Hello.
    I tried 'tkinter_split.patch' patch against 3.3.2, but a fix for grid_info function is also needed.

    #test.py
    import tkinter as tk
    
    root = tk.Tk()
    b = tk.Button(root, text='Button')
    b.grid()
    print(b.grid_info())
    root.mainloop()

    Here's is the script's output:

    alejandro@vostro1:~/tmp$ cpython3.3 test.py 
    Traceback (most recent call last):
      File "test.py", line 10, in <module>
        print(b.grid_info())
      File "/home/alejandro/apps/cpython3.3.2/lib/python3.3/tkinter/__init__.py", line 2024, in grid_info
        if value[:1] == '.':
    TypeError: '_tkinter.Tcl_Obj' object is not subscriptable

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Aug 22, 2013

    New changeset 6b841e1ee3b8 by Serhiy Storchaka in branch '3.3':
    Issue bpo-16809: Tkinter's splitlist() and split() methods now accept Tcl_Obj
    http://hg.python.org/cpython/rev/6b841e1ee3b8

    New changeset 85285e6e28f4 by Serhiy Storchaka in branch 'default':
    Issue bpo-16809: Tkinter's splitlist() and split() methods now accept Tcl_Obj
    http://hg.python.org/cpython/rev/85285e6e28f4

    New changeset 2d96764a66fa by Serhiy Storchaka in branch '2.7':
    Issue bpo-16809: Tkinter's splitlist() and split() methods now accept Tcl_Obj
    http://hg.python.org/cpython/rev/2d96764a66fa

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Aug 22, 2013

    New changeset 516b0cd87a90 by Serhiy Storchaka in branch '3.3':
    Issue bpo-16809: Fixed some tkinter incompabilities with Tcl/Tk 8.6.
    http://hg.python.org/cpython/rev/516b0cd87a90

    New changeset 5b5ef012cd4e by Serhiy Storchaka in branch 'default':
    Issue bpo-16809: Fixed some tkinter incompabilities with Tcl/Tk 8.6.
    http://hg.python.org/cpython/rev/5b5ef012cd4e

    New changeset 06244031b608 by Serhiy Storchaka in branch '2.7':
    Issue bpo-16809: Fixed some tkinter incompabilities with Tcl/Tk 8.6.
    http://hg.python.org/cpython/rev/06244031b608

    @serhiy-storchaka
    Copy link
    Member

    Thank you alejandro. Fixed.

    I'm afraid this is not all problems with 8.6 and so left this issue open.

    @serhiy-storchaka
    Copy link
    Member

    Since there are no other reports about 8.6 I close this issue.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    topic-tkinter type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant