New-Style-Classes: some questions

Tino Lange tl_news at nexgo.de
Tue Mar 12 10:02:37 EST 2002


Hi!

I'm trying to use the new, cool 2.2-feature of deriving own classes from 
builtin types. For one application I thought it could be useful to have a 
list that has a maximum size and throws away the first elements if new 
elements are appended at the othe end (it's name should be MaxSizedList)

OK, implementing something like that is no problem at all. The new 
list-like class works quite fine.

But testing it I found two problems/questions:

1) According to the current documentation
 
http://www.python.org/doc/current/ref/sequence-methods.html

the special methods __getslice__ and __setslice__ are deprecated and should 
not be implemented anymore (since 2.0) . But they exist automatically in 
the subclassed list and are used for insertion like 

newlist[3:4] = 5

- so it seems I have to code/overload these deprecated methods. What's true 
now? Deprecated or not?

2) I wanted to transfer the MaxSizedList on request via XML-RPC. But 
xmlrpclib only nows about "real" lists. And there seems to be no interface 
to add dump()-Methods for other data types, or?

So the best solution is to transport an object like
return list(newlist)

But I guess this makes a temporary copy of my MaxSizedList just for the 
XML-RPC-transport, or? So it's horrible inefficient? Is there no other way 
to deal with subclassed types in this lib besides patching the xmlrpclib to 
know my MaxSizedList? Is there a kind of casting to a "normal" list 
possible without making a completely new list from the MaxSizedList-Content?

Thanks a lot for your help!

Tino

  





More information about the Python-list mailing list