[Python-bugs-list] [ python-Bugs-729317 ] comparing versions - one a float

SourceForge.net noreply@sourceforge.net
Sun, 18 May 2003 22:28:37 -0700


Bugs item #729317, was opened at 2003-04-29 05:41
Message generated for change (Comment added) made by loewis
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=729317&group_id=5470

Category: Tkinter
Group: Python 2.3
Status: Open
Resolution: None
Priority: 6
Submitted By: Larry Bugbee (thunderbug)
Assigned to: Martin v. Löwis (loewis)
Summary: comparing versions - one a float

Initial Comment:
Tkinter.py, line 1572, 2.3b1 from python.org....

Attempts to compare tcl_version with
_tkinter.TCL_VERSION.  Both have the same value, 8.4,
but...

    tcl_version is a <type 'float'> and
    _tkinter.TCL_VERSION is a <type 'str'>

Temporary kludge: wrap it...    str(tcl_version)


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

>Comment By: Martin v. Löwis (loewis)
Date: 2003-05-19 07:28

Message:
Logged In: YES 
user_id=21627

I disagree that patch #518625 is in error; _tkinter uses
only official Tcl API to access Tcl objects. It is certainly
the case that a computation with tcl_version may cause it to
change its type from string. However, I would still like to
find out where exactly that happens on the Mac, as it
happens nowhere else, and Tkinter most certainly does not
use any Tcl code that may trigger such a change.

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

Comment By: Jack Jansen (jackjansen)
Date: 2003-05-18 23:22

Message:
Logged In: YES 
user_id=45365

Martin, I'm assigning back to you, because I'm out of my water here. I 
discussed this problem with the MacTcl people, and it seems that what was 
checked in in _tkinter.c for patch 518625 is not correct: if something is 
initialized as a string in Tcl and then some code accesses it as a float the 
internal float representation will be created automatically. In other words:
the FromObj() code attempts to graft Python semantics on Tcl objects, which 
is prone to obscure errors.

Here are some excerpts from relevant mail messages:

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

>From Jim Ingham:
tcl_version is created as a string variable with the value "8.2".  If somebody 
tried to do some math with it (like evaluate expr $tcl_version <= 8.4 or 
something) then Tcl would set the internal representation to a float.  I don't 
see any place where we are doing that, but maybe your Tkinter code does 
that to check something on Mac OS X?

Anyway that would not be an error on Tcl's part.  If you want tcl_version in 
Python explicitly as a string, you need to make sure the string representation 
exists, and then get the variable as a string.  You can't rely on their being or 
not being any particular internal representation.

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

And from Benjamin Riefenstahl:
Well, somebody may already have told you that, but that's not how Tcl
works.  In Tcl *all* values are strings.  You use
Tcl_GetStringFromObj() to get that value.  That's it.  If you want a
floating point, you explicitly *convert* by using
Tcl_GetDoubleFromObj().

Everything you see related to "types" is just internal speed
optimizations to avoid double conversions.  These internal
representations come and go at the whim of the implementation.
Accessing these infos without the official APIs will lead to errors
and inconsistent behaviour, as you have seen.  The details of the
behaviour will also quite likely change from Tcl version to Tcl
version.
---------------


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

Comment By: Martin v. Löwis (loewis)
Date: 2003-05-10 09:29

Message:
Logged In: YES 
user_id=21627

This seems to happen only in the Mac version of Tcl. I can't
reproduce it on Linux or Windows, and I can't see anything
in the Tcl sources that may causing it.

tcl_version is set in generic/tclBasic.c using Tcl_SetVar,
i.e. as a string. It is never referred-to in the Tcl
sources, except for being returned from 'info tclversion'.
So I can't see why it would ever be changed to a floating
point object.

Perhaps the Mac is not using the original Tcl source code?
Assigning to Jack for further investigation.

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

Comment By: Larry Bugbee (thunderbug)
Date: 2003-05-10 04:44

Message:
Logged In: YES 
user_id=10953

Several of us have encountered this.  Personally, I have seen this with 
Tcl/Tk 8.4.1 under Mac OS X 10.2.4 and MacPython 2.3a2.  ...and with 
Tcl/Tk 8.4.2.  ...and under 10.2.5 and 2.3b1.  I've tried several 
combinations.  

My sources came from ftp://ftp.python.org and http://ftp.cwi.nl/jack/
python/mac/ .  I hope this helps.  

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

Comment By: Martin v. Löwis (loewis)
Date: 2003-05-09 10:50

Message:
Logged In: YES 
user_id=21627

I cannot reproduce this. What operating system is this, what
is the precise Tcl version, and where can I get the source
code of this Tcl version?

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

Comment By: Raymond Hettinger (rhettinger)
Date: 2003-05-07 00:00

Message:
Logged In: YES 
user_id=80475

Martin, is this something you can look at in Eric's absence?

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

Comment By: Raymond Hettinger (rhettinger)
Date: 2003-04-29 07:00

Message:
Logged In: YES 
user_id=80475

Eric,  I think this was your change.

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

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=729317&group_id=5470