PyShadowString test, ideas, questions

Jeff Allen <[email protected]>
Newsgroups gmane.comp.lang.jython.devel
Message-ID <[email protected]>
I've added a test for PyShadowString, our string that can have two 
values at once. Trying to design a test raises some questions.

 >>> s = PyShadowString("hello", "bonjour")
 >>> s == 'bonjour'
False
 >>> s.addtarget(r"org\.python\.util\.InteractiveConsole")
 >>> s == 'bonjour'
True

So far so good.

1. Should I be able to do this?

 >>> s.gettargets().pop()
('org\\.python\\.util\\.InteractiveConsole',)
 >>> s == 'bonjour'
False

2. This seems like a useful "unconditional", but I wonder if it is harmful:

 >>> s.addtarget(None)
 >>> s == 'bonjour'
True

3. Confusing subject, but I'm not sure the exposure of __eq__ is 
"canonical". I think the convention is __eq__ just wraps 
shadowstr___eq__, as done for startswith and __repr__, but here there is 
"added value" in __eq__ (also in PyString.__eq__). shadowstr___eq__ will 
be exposed as __eq__, and shouldn't PyShadowString.__eq__ do the same 
thing? What we need is complicated by the wrapper PyObject._eq.

4. Single-stepping through __eq__ I notice that a call like s == 
'bonjour' (i.e. a call to __eq__) is quite costly, even when there are 
no targets that match. The problem is in isTarget() and so I think I 
will try changing the logic to:

return other==string || (other==shadow && isTarget())

but also, we can make isTarget() cheaper.

5. I tried the tests of str on PyShadowString, to prove it is also a 
str, but they fail because it cannot be sub-classed. Is there a reason 
to prevent sub-classing?

6. And relatedly, when I was working on PyType I noticed that it is 
possible to expose a Java sub-class as the same Python type as its 
parent. This would mean that type(PyShadowString("a", "b")) would be str 
even though the behaviour is different. This sounds worth trying.

Jeff

-- 
Jeff Allen

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot

_______________________________________________
Jython-dev mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jython-dev
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.