Title: issue of the key word "is not"
Type: behaviour Severity: critical
Components: Core Versions: 2.5.0
Status: closed Resolution: invalid
Dependencies: Superseder:
Assigned To: fwierzbicki Nosy List: asnama, fwierzbicki, thobes
Priority: high Keywords:

Created on 2009-09-17.03:38:31 by asnama, last changed 2009-09-17.09:01:50 by thobes.

File name Uploaded Description Edit Remove asnama, 2009-09-17.06:44:36 asnama, 2009-09-17.07:01:07 asnama, 2009-09-17.07:12:38 another test script
msg5171 (view) Author: Lance (asnama) Date: 2009-09-17.03:38:30
When I use the Google Calendar APIs and Tools, I test this function.

# \gdata\calendar\, line 490
  def _SetOrderBy(self, val):
    if val is not 'lastmodified' and val is not 'starttime':
      raise Error, "Order By must be either 'lastmodified' or 'starttime'"
    self['orderby'] = val

I got error no matter what I passed to it.

Jython 2.5.0 (Release_2_5_0:6476, Jun 16 2009, 13:33:26)
[Java HotSpot(TM) Client VM (Sun Microsystems Inc.)] on java1.6.0_14
Type "help", "copyright", "credits" or "license" for more information.
>>> def t(v):
...   if v is not 'a' and v is not 'b': return 'e'
...   return 't'
>>> t('a')
>>> t('b')
>>> t('c')
msg5172 (view) Author: Frank Wierzbicki (fwierzbicki) Date: 2009-09-17.03:51:37
That's a strange one -- I can't reproduce this in a file, but in
interactive mode it breaks as reported, suggesting (to me) that the
problem is in parsing in single mode...
msg5173 (view) Author: Tobias Ivarsson (thobes) Date: 2009-09-17.06:14:16
This has to do with string interning.
When executed in a file we discover all the occurrences of the same
string and use the same object for them (the same as CPython), but when
running in interactive mode we use new string objects for all strings
that are in different compilation units. CPython does it this way to.
The reason this is not working is because 'is' (and 'is not') is an
identity equals comparison, it returns true if the objects are the same,
and should not be used to compare strings. For string comparison '=='
and '!=' should be used.

The reason the example works in CPython is that the strings are
"identifier looking strings", i.e. strings that are valid as
identifiers, and CPython interns all such strings since it improves
performance there. Jython does not intern strings like that.

If you instead try this code (again in interactive mode) it will behave
the same in CPython as in Jython:

>>> def t(v):
...     if v is not 'this string object': return 'e'
...     return 't'
>>> t('this string object')
msg5174 (view) Author: Lance (asnama) Date: 2009-09-17.06:44:36
But when I run the, it still error. Please advise how can I run
it under Jython.

Traceback (most recent call last):
  File "", line 15, in <module>
    query.orderby = 'lastmodified'
  File "...\Lib\site-packages\gdata\calendar\", line 492, in
    raise Error, "Order By must be either 'lastmodified' or 'starttime'"
gdata.calendar.service.Error: Order By must be either 'lastmodified' or
msg5175 (view) Author: Lance (asnama) Date: 2009-09-17.07:01:07
I also upload the for your reference.
msg5176 (view) Author: Tobias Ivarsson (thobes) Date: 2009-09-17.07:04:24
From where I'm standing this looks like a bug in the gdata API. CPython
does intern these kinds of strings, but there are no guarantees in
Python as a language that this kind of interning will be done. The 'is'
comparator is an identity equals comparator, nothing else. And interning
of strings that look like identifiers is a performance optimization in
CPython, any code comparing strings with 'is'/'is not' when identity
equality isn't what they are after (this is almost never the case with
strings) is faulty.
msg5177 (view) Author: Lance (asnama) Date: 2009-09-17.07:12:38
The issue maybe cause by the class from dict, please find the update
test script
msg5178 (view) Author: Tobias Ivarsson (thobes) Date: 2009-09-17.07:34:04
The issue that you are experiencing is not related to the subscript
assignment to self. The exception occurs before that. Your first
identification of where the problem occurs is correct, but it's not an
error in Jython but in gdata.calendar.service, the developers at Google
ought to know better than to use identity equals for string comparison,
but I guess we all make mistakes...
The sortorder property has the same issue.
Please report the issue to the gdata API instead:
msg5179 (view) Author: Tobias Ivarsson (thobes) Date: 2009-09-17.08:18:11
It's even wrong to use 'is' for comparing integers in CPython, even
regular integers (as opposed to long integers), try the following in
>>> a = 1<<10
>>> b = 1<<10
>>> a is b

This would however be True for small integers in both CPython and
Jython, since both implementations have a "small integer cache":
>>> a = 1 << 8
>>> b = 1 << 8
>>> a is b

But again, this is not something you should rely on.
msg5180 (view) Author: Lance (asnama) Date: 2009-09-17.08:42:06
ok, thanks for your support. I will report the issue to Google then.
msg5181 (view) Author: Tobias Ivarsson (thobes) Date: 2009-09-17.09:01:49
This is an issue in the gdata API, and have been reported accordingly:
Date User Action Args
2009-09-17 09:01:50thobessetstatus: open -> closed
resolution: accepted -> invalid
messages: + msg5181
2009-09-17 08:42:06asnamasetmessages: + msg5180
2009-09-17 08:18:12thobessetmessages: + msg5179
2009-09-17 07:34:05thobessetmessages: + msg5178
2009-09-17 07:12:39asnamasetfiles: +
messages: + msg5177
2009-09-17 07:04:24thobessetmessages: + msg5176
2009-09-17 07:01:10asnamasetfiles: +
messages: + msg5175
2009-09-17 06:44:37asnamasetfiles: +
messages: + msg5174
2009-09-17 06:14:17thobessetnosy: + thobes
messages: + msg5173
2009-09-17 03:51:38fwierzbickisetpriority: high
assignee: fwierzbicki
resolution: accepted
messages: + msg5172
nosy: + fwierzbicki
2009-09-17 03:38:31asnamacreate