classification
Title: Implement nb_nonzero for PyTclObject
Type: enhancement Stage: patch review
Components: Tkinter Versions: Python 3.2
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: BreamoreBoy, gpolo, loewis, mark.dickinson
Priority: normal Keywords: patch

Created on 2008-11-18 14:01 by gpolo, last changed 2012-03-13 21:31 by loewis. This issue is now closed.

Files
File name Uploaded Description Edit
_tkinter__nonzero__.diff gpolo, 2008-11-18 14:01
Messages (7)
msg76008 - (view) Author: Guilherme Polo (gpolo) * (Python committer) Date: 2008-11-18 14:01
Implementing it makes this "crazy" check in
http://bugs.python.org/issue3767
(http://bugs.python.org/file12043/tkColorChooser.diff) be no longer needed
msg112871 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2010-08-04 19:37
The patch changes _tkinter.c so can a C guru take a look please.
msg112878 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-08-04 20:02
I'd call this a new feature;  removing 2.7 and 3.1 from versions.

The patch needs updating for py3k, which should be a fairly simple task.

I don't know much about Tcl, but wouldn't this change give quite confusing results for numeric values?  Presumably, all integers and floats would have a bool() of True?  (Or am I misunderstanding?)  I'm not sure what the value of implementing __nonzero__ is if it only works as expected for strings.
msg112881 - (view) Author: Guilherme Polo (gpolo) * (Python committer) Date: 2010-08-04 20:14
Mark,

If you want to expand it to handle other data types, I'm ok with it
but I predict troubles for you. The problem is that in Tcl there is
only one "real" data type -- string. Depending on how you operate over
a value it is then, internally, treated as something more specific but
this is not directly exposed for the "API users".
msg112883 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-08-04 20:21
> If you want to expand it to handle other data types, I'm ok with it
> but I predict troubles for you.

Yes, I suspected as much.  I don't know much Tcl, but I'm definitely prepared to believe you on this point. :)  I'd be fine with this patch if there's some documentation somewhere that points out that the bool() might give unexpected results (for Python users) for zeros, empty lists, etc.

I assume that Tcl_GetCharLength works for any object, regardless of its internal representation?

Can you update the patch for py3k, and add docs and tests?
msg112893 - (view) Author: Guilherme Polo (gpolo) * (Python committer) Date: 2010-08-04 21:01
> I assume that Tcl_GetCharLength works for any object, regardless of
> its internal representation?

I didn't look at its code but I assume it will create a string representation for the object in question if there isn't one in place when the call happens, so this means I /believe/ it will work for any Tcl object.

> Can you update the patch for py3k, and add docs and tests?

I can do it (maybe the test part may not be excellent), but not at this moment.

Btw, I'm happy that you mentioned that doc requirement about unexpected results because I was going to write about it in my previous reply but I thought my English could hurt its meaning and negatively affect you.
msg155670 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2012-03-13 21:31
I'm closing the issue. People who want to check for an empty string representation can just convert the tcl objects to strings themselves. I agree with Mark that implementing nonzero is too ambiguous.
History
Date User Action Args
2012-03-13 21:31:15loewissetstatus: open -> closed

nosy: + loewis
messages: + msg155670

resolution: rejected
2010-08-04 21:01:35gpolosetmessages: + msg112893
2010-08-04 20:21:22mark.dickinsonsetmessages: + msg112883
2010-08-04 20:14:10gpolosetmessages: + msg112881
2010-08-04 20:02:30mark.dickinsonsetversions: - Python 3.1, Python 2.7
nosy: + mark.dickinson

messages: + msg112878

type: enhancement
2010-08-04 19:37:46BreamoreBoysetversions: + Python 3.1, Python 3.2, - Python 2.6, Python 3.0
nosy: + BreamoreBoy

messages: + msg112871

stage: patch review
2008-11-18 14:01:14gpolocreate