UserDict deprecated

U

Uwe Mayer

Hi,

Why is the UserDict module is deprecated after Python 2.2. The application
of it I have in mind is, i.e. multiple inheritance from "file" and "dic" -
which is not possible.
If I used UserDict I would not need to specify all methods UserDict provides
alreay, anyway.

Ciao
Uwe
 
H

Hans Nowak

Uwe said:
Why is the UserDict module is deprecated after Python 2.2. The application
of it I have in mind is, i.e. multiple inheritance from "file" and "dic" -
which is not possible.

I am curious, what would you do with a class that derives from both file
and dict?
 
U

Uwe Mayer

I am curious, what would you do with a class that derives from both file
and dict?

I was writing a class that read /writes some binary file format. I
implemented the functions from the file interface such that they are
refering to records. However, the file format has some header fields and
I'd wanted to grant access to those via the dict-interface.

Another example: working with PyQt I have an instance of a QListView and
wanted to use the list-interface to get and set individual records.

Ciao
Uwe
 
H

Hans Nowak

Uwe said:
[...]

I was writing a class that read /writes some binary file format. I
implemented the functions from the file interface such that they are
refering to records. However, the file format has some header fields and
I'd wanted to grant access to those via the dict-interface.

Another example: working with PyQt I have an instance of a QListView and
wanted to use the list-interface to get and set individual records.

If it's just a matter of attribute access, implementing the relevant
__getitem__ and __setitem__ methods will probably suffice. I don't
think that deriving from dict or list will do you much good here... most
of the methods will be irrelevant, or won't do what you want, so you
have to override them anyway.
 
S

Steven Bethard

Uwe said:
I was writing a class that read /writes some binary file format. I
implemented the functions from the file interface such that they are
refering to records. However, the file format has some header fields and
I'd wanted to grant access to those via the dict-interface.

If you implemented the file interface functions yourself, why do you
want to inherit from file?
Another example: working with PyQt I have an instance of a QListView and
wanted to use the list-interface to get and set individual records.

But just inheriting from list won't make this work, will it? Don't you
want to do something like:

class C(QListView):
def __getitem__(self, i):
return self.getIndividualRecord(i) # or whatever method gives
# you the record


Steve
 
A

Alex Martelli

Uwe Mayer said:
If I used UserDict I would not need to specify all methods UserDict provides
alreay, anyway.

The DictMixin class from the UserDict module is *not* deprecated -- only
the UserDict class from the same module. (If you found info saying
otherwise pls provide a URL: the info is wrong and I'll try to get it
fixed -- thanks!). DictMixin's purpose is exactly as you state: letting
you make a complete mapping class out of one which only supplies the
very basics, by mix-in inheritance.


Alex
 
U

Uwe Mayer

Saturday 01 January 2005 23:34 pm Steven Bethard wrote:

[...]
If you implemented the file interface functions yourself, why do you
want to inherit from file?
[...]

But just inheriting from list won't make this work, will it? Don't you
want to do something like:

[...]

Right. I guess the thing I was looking for is an interface specification as
in Java's Interfaces.
I could write an abstract base class, where all methods just raise
NotImplemented().

I don't know wether this is a good idea after all...:/

Thanks
Uwe
 
W

Wolfgang

Hello,

Alex said:
The DictMixin class from the UserDict module is *not* deprecated -- only
the UserDict class from the same module. (If you found info saying
otherwise pls provide a URL: the info is wrong and I'll try to get it
fixed -- thanks!). DictMixin's purpose is exactly as you state: letting
you make a complete mapping class out of one which only supplies the
very basics, by mix-in inheritance.

If UserDict is deprecated why is it still used in the os module ?
(in python V. 2.4)

The std lib should be a good example for python coding, if something
is deprecated it should not be used in the std lib.

Some weeks ago I had ten minutes of spare time and rewrote the 'os'
module to use dict and there was no problem with it.
But due to lack of time I was not able to run tests and submitted no
patch. I will try this next week.

bye by Wolfgang
 
S

Steve Holden

Wolfgang said:
Hello,




If UserDict is deprecated why is it still used in the os module ?
(in python V. 2.4)

The std lib should be a good example for python coding, if something
is deprecated it should not be used in the std lib.

Some weeks ago I had ten minutes of spare time and rewrote the 'os'
module to use dict and there was no problem with it.
But due to lack of time I was not able to run tests and submitted no
patch. I will try this next week.

bye by Wolfgang
Good for you! When you've fixed that up, you might want to take a look
at cgi.py, dumbdbm.py, shelve.py and weakref.py as well ;-)

regards
Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top