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.ttk._val_or_dict assumes tkinter._default_root exists #65601

Closed
Zero mannequin opened this issue Apr 30, 2014 · 13 comments
Closed

tkinter.ttk._val_or_dict assumes tkinter._default_root exists #65601

Zero mannequin opened this issue Apr 30, 2014 · 13 comments
Assignees
Labels
stdlib Python modules in the Lib dir topic-tkinter type-bug An unexpected behavior, bug, or error

Comments

@Zero
Copy link
Mannequin

Zero mannequin commented Apr 30, 2014

BPO 21402
Nosy @terryjreedy, @zware, @serhiy-storchaka
Files
  • ttk_val_or_dict.patch
  • 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 2014-05-28.15:51:18.900>
    created_at = <Date 2014-04-30.19:22:43.168>
    labels = ['expert-tkinter', 'type-bug', 'library']
    title = 'tkinter.ttk._val_or_dict assumes tkinter._default_root exists'
    updated_at = <Date 2019-10-31.14:23:06.231>
    user = 'https://bugs.python.org/Zero'

    bugs.python.org fields:

    activity = <Date 2019-10-31.14:23:06.231>
    actor = 'Zero'
    assignee = 'serhiy.storchaka'
    closed = True
    closed_date = <Date 2014-05-28.15:51:18.900>
    closer = 'serhiy.storchaka'
    components = ['Library (Lib)', 'Tkinter']
    creation = <Date 2014-04-30.19:22:43.168>
    creator = 'Zero'
    dependencies = []
    files = ['35341']
    hgrepos = []
    issue_num = 21402
    keywords = ['patch']
    message_count = 13.0
    messages = ['217644', '217645', '217656', '217807', '218485', '218505', '218527', '218561', '218563', '218564', '219053', '219280', '219282']
    nosy_count = 5.0
    nosy_names = ['terry.reedy', 'gpolo', 'python-dev', 'zach.ware', 'serhiy.storchaka']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue21402'
    versions = ['Python 2.7', 'Python 3.4', 'Python 3.5']

    @Zero
    Copy link
    Mannequin Author

    Zero mannequin commented Apr 30, 2014

    If a call is made to tkinter.NoDefaultRoot, then calls to tkinter.ttk._val_or_dict may fail. NoDefaultRoot ends with "del _default_root" (line 174) and removes the variable from the module's namespace. _val_or_dict can try to access this variable but assumes that it exists (line 319). If _default_root does not exist, the function will raise an AttributeError: 'module' object has no attribute '_default_root'.

    @Zero Zero mannequin added type-crash A hard crash of the interpreter, possibly with a core dump stdlib Python modules in the Lib dir topic-tkinter labels Apr 30, 2014
    @zware
    Copy link
    Member

    zware commented Apr 30, 2014

    Can you provide an example of when this happens? Note that tkinter.ttk._val_or_dict is a private function and should not be called by user code.

    @zware zware added type-bug An unexpected behavior, bug, or error and removed type-crash A hard crash of the interpreter, possibly with a core dump labels Apr 30, 2014
    @Zero
    Copy link
    Mannequin Author

    Zero mannequin commented Apr 30, 2014

    I discovered the problem when trying to run the program listed at
    http://code.activestate.com/recipes/577633/ (Directory Pruner 2).

    @terryjreedy
    Copy link
    Member

    A reference to a non-existent attribute fails no matter who calls the function. Stephen, can you suggest a patch, perhaps based on code in other functions that try to access _default_root?

    @Zero
    Copy link
    Mannequin Author

    Zero mannequin commented May 13, 2014

    It seems that most functions and methods do not bother checking if _default_root exists before trying to access it. However, upon seeing line 366 in ttk (if tkinter._support_default_root:), my recommendation would be to change line 319 to "if tkinter._support_default_root and tkinter._default_root:" to fix the problem. Several similar lines appear in tkinter\init.py at locations 1835, 1845, and 2050.

    @serhiy-storchaka
    Copy link
    Member

    This is not so easy, because it does not work with wantobject=False and can not work with future versions of Tk. Actually we should use self.tk instead of _default_root, but this will change the signature of _list_from_layouttuple() and _val_or_dict(). Due to the risk of breaking existing user code which uses these private functions, they should be left with old signature and new functions should be added.

    @serhiy-storchaka serhiy-storchaka self-assigned this May 14, 2014
    @Zero
    Copy link
    Mannequin Author

    Zero mannequin commented May 14, 2014

    There is discussion of removing wantobjects in bpo-3015. If it gets removed, a better patch might be created for future versions of tkinter. However, accessing self.tk would probably be a good replacement for anywhere tkinter._default_root can be found (except in cases where a widget is not given a parent).

    @terryjreedy
    Copy link
    Member

    Due to the risk of breaking existing user code which uses these private functions, they should be left with old signature and new functions should be added.

    The reason we make things private is so we don't have to do this. Why would you make an exception here?

    @serhiy-storchaka
    Copy link
    Member

    Because there are explicit tests for these private functions.

    @Zero
    Copy link
    Mannequin Author

    Zero mannequin commented May 14, 2014

    Because there are explicit tests for these private functions.

    Does that not mean that both the functions and their explicit tests should be changed?

    @serhiy-storchaka
    Copy link
    Member

    Well, if we allow to change signature of theses functions, here is a patch which fixes _list_from_layouttuple and _val_or_dict and rewrites tests. Mocked TkApp is used because test_functions should run without the gui resource enabled.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented May 28, 2014

    New changeset 8e5c65719c12 by Serhiy Storchaka in branch '2.7':
    Issue bpo-21402: tkinter.ttk now works when default root window is not set.
    http://hg.python.org/cpython/rev/8e5c65719c12

    New changeset 4a0987b8f630 by Serhiy Storchaka in branch '3.4':
    Issue bpo-21402: tkinter.ttk now works when default root window is not set.
    http://hg.python.org/cpython/rev/4a0987b8f630

    New changeset c112a91ad609 by Serhiy Storchaka in branch 'default':
    Issue bpo-21402: tkinter.ttk now works when default root window is not set.
    http://hg.python.org/cpython/rev/c112a91ad609

    @serhiy-storchaka
    Copy link
    Member

    Thank you for your report Stephen.

    @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
    stdlib Python modules in the Lib dir topic-tkinter type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants