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 and getdouble should support Tcl_Obj #68068

Closed
serhiy-storchaka opened this issue Apr 7, 2015 · 6 comments
Closed

Tkinter: getint and getdouble should support Tcl_Obj #68068

serhiy-storchaka opened this issue Apr 7, 2015 · 6 comments
Assignees
Labels
extension-modules C modules in the Modules dir topic-tkinter type-feature A feature request or enhancement

Comments

@serhiy-storchaka
Copy link
Member

BPO 23880
Nosy @terryjreedy, @serhiy-storchaka
Files
  • tkinter_getxxx_tclobj.patch
  • tkinter_getxxx_tclobj-3.4.patch
  • tkinter_getxxx_tclobj-2.7.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 2015-05-06.11:03:09.160>
    created_at = <Date 2015-04-07.08:41:03.977>
    labels = ['extension-modules', 'type-feature', 'expert-tkinter']
    title = 'Tkinter: getint and getdouble should support Tcl_Obj'
    updated_at = <Date 2015-05-06.11:03:09.159>
    user = 'https://github.com/serhiy-storchaka'

    bugs.python.org fields:

    activity = <Date 2015-05-06.11:03:09.159>
    actor = 'serhiy.storchaka'
    assignee = 'serhiy.storchaka'
    closed = True
    closed_date = <Date 2015-05-06.11:03:09.160>
    closer = 'serhiy.storchaka'
    components = ['Extension Modules', 'Tkinter']
    creation = <Date 2015-04-07.08:41:03.977>
    creator = 'serhiy.storchaka'
    dependencies = []
    files = ['38855', '39192', '39193']
    hgrepos = []
    issue_num = 23880
    keywords = ['patch']
    message_count = 6.0
    messages = ['240196', '240221', '240223', '241935', '242654', '242655']
    nosy_count = 3.0
    nosy_names = ['terry.reedy', 'python-dev', 'serhiy.storchaka']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue23880'
    versions = ['Python 3.5']

    @serhiy-storchaka
    Copy link
    Member Author

    getint, getdouble and getboolean were thin wrappers around Tcl functions that converted string result of Tcl call to specified Python type. Since 2.3 _tkinter can return not only string, but int, float, etc and Tcl_Obj (if wantobject is True). getXXX methods was updated to work with respective automatically converted types (getint with int, etc), but they don't work with general Tcl_Obj, so can't be applied to the result of _tkinter call in general case. As a workaround you should use int(str(value)) or like.

    Support of Tcl_Obj in getbool was added in bpo-15133. Proposed patch adds support of Tcl_Obj in getint and getdouble and int in getdouble. It also restores the use of getint and getdouble in Tkinter.

    @serhiy-storchaka serhiy-storchaka added extension-modules C modules in the Modules dir topic-tkinter type-feature A feature request or enhancement labels Apr 7, 2015
    @terryjreedy
    Copy link
    Member

    I don't quite understand this, but I think I should. Here are preliminary questions.

    1. It seems that this pushes conversions from python code (app.py, tkinter.py) to C (_tkinter.py). Correct? What is being gained from a user viewpoint?

    2. "getint, getdouble and getboolean were thin wrappers around Tcl functions that converted string result of Tcl call to specified Python type."

    How does this match getint and getdouble being synonyms for builtins?

    • getint = int
    • getdouble = float
      Or were 'int' and 'float' overriden before this?
    1. Does the change break existing code? In particular, is the idlelib change necessary or optional?

    2. Should there be a doc change, at least in docstrings?

    @serhiy-storchaka
    Copy link
    Member Author

    1. It seems that this pushes conversions from python code (app.py, tkinter.py) to C (_tkinter.py). Correct? What is being gained from a user viewpoint?

    The benefit is that widget.tk.getint(widget.tk.call(...)) (and widget.getint(widget.call(...))) always works when it makes sense. Currently it works for integers and strings. If the result of Tcl call becomes some specific type in new Tcl version, this needs a workaround with converting to str, as you can see in IDLE code. User code with this patch will become more robust against future Tcl/Tk changes. And actually against changes that already happen in recent Tcl versions. Many user code that worked with 8.3 or 8.4 needed an update to work with 8.5 or 8.6. With this patch they perhaps need less changes.

    1. Does the change break existing code?

    Usually not.

    In particular, is the idlelib change necessary or optional?

    It is optional. It is is just a demonstration how the code can be made simpler and more robust.

    How does this match getint and getdouble being synonyms for builtins?

    • getint = int
    • getdouble = float
      Or were 'int' and 'float' overridden before this?

    There are different functions on different levels. There are tkapp methods in _tkinter.c. There are Misc methods in tkinter.py (added in changesets 73dd2a979857 and 273451892327). They originally was wrappers around tkapp methods. There are module-level functions in tkinter.py. They were converted to aliases of int and float in 34cca832a4af.

    1. Should there be a doc change, at least in docstrings?

    Unfortunately all these functions are not documented.

    @serhiy-storchaka
    Copy link
    Member Author

    > 2. Does the change break existing code?

    Usually not.

    I meant that the only difference (except that now Tkinter can work in cases where it failed before) is that that some exceptions can change its type from ValueError to TclError. But first, these exception are unlikely raised, and second, getint() and getdouble() are used to convert the result of call(), that can raise a TclError, so this doesn't add new exception type.

    However, to decrease even such minor probability of the breakage, the patch for 3.4 and 2.7 uses widget.getint() instead of widget.tk.getint(). This wrapper converts TclError to ValueError.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented May 6, 2015

    New changeset cb80dd82d3da by Serhiy Storchaka in branch 'default':
    Issue bpo-23880: Tkinter's getint() and getdouble() now support Tcl_Obj.
    https://hg.python.org/cpython/rev/cb80dd82d3da

    @serhiy-storchaka
    Copy link
    Member Author

    Committed in the default branch only. If other issues with Tcl/Tk 8.5 or 8.6 will be reported, we could apply general solution instead of particular workarounds in maintained branches too.

    @serhiy-storchaka serhiy-storchaka self-assigned this May 6, 2015
    @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
    extension-modules C modules in the Modules dir topic-tkinter type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants