UserDict deprecated

Discussion in 'Python' started by Uwe Mayer, Jan 1, 2005.

  1. Uwe Mayer

    Uwe Mayer Guest

    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
     
    Uwe Mayer, Jan 1, 2005
    #1
    1. Advertising

  2. Uwe Mayer

    Hans Nowak Guest

    Uwe Mayer wrote:

    > 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?

    --
    Hans Nowak
    http://zephyrfalcon.org/
     
    Hans Nowak, Jan 1, 2005
    #2
    1. Advertising

  3. Uwe Mayer

    Uwe Mayer Guest

    Saturday 01 January 2005 22:48 pm Hans Nowak wrote:

    > Uwe Mayer wrote:
    >
    >> 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?


    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
     
    Uwe Mayer, Jan 1, 2005
    #3
  4. Uwe Mayer

    Hans Nowak Guest

    Uwe Mayer wrote:

    >>>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 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.

    --
    Hans Nowak
    http://zephyrfalcon.org/
     
    Hans Nowak, Jan 1, 2005
    #4
  5. Uwe Mayer wrote:
    > Saturday 01 January 2005 22:48 pm Hans Nowak wrote:
    >>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.


    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
     
    Steven Bethard, Jan 1, 2005
    #5
  6. Uwe Mayer <> wrote:
    ...
    > 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
     
    Alex Martelli, Jan 1, 2005
    #6
  7. Uwe Mayer

    Uwe Mayer Guest

    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
     
    Uwe Mayer, Jan 2, 2005
    #7
  8. Uwe Mayer

    Wolfgang Guest

    Hello,

    Alex Martelli wrote:

    > 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
     
    Wolfgang, Jan 2, 2005
    #8
  9. Uwe Mayer

    Steve Holden Guest

    Wolfgang wrote:

    > Hello,
    >
    > Alex Martelli wrote:
    >
    >> 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
    >

    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
    --
    Steve Holden http://www.holdenweb.com/
    Python Web Programming http://pydish.holdenweb.com/
    Holden Web LLC +1 703 861 4237 +1 800 494 3119
     
    Steve Holden, Jan 3, 2005
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Barney Barumba
    Replies:
    0
    Views:
    565
    Barney Barumba
    Jul 23, 2003
  2. Andreas Kuntzagk
    Replies:
    1
    Views:
    348
    Steven Taschuk
    Jul 22, 2003
  3. Alex Martelli

    UserDict question

    Alex Martelli, Nov 4, 2003, in forum: Python
    Replies:
    2
    Views:
    303
    Guyon Morée
    Nov 4, 2003
  4. John Lenton

    misguiding docs in 2.3's UserDict ?

    John Lenton, Jul 6, 2004, in forum: Python
    Replies:
    0
    Views:
    304
    John Lenton
    Jul 6, 2004
  5. Steven Bethard
    Replies:
    8
    Views:
    403
    Nick Coghlan
    Jan 5, 2005
Loading...

Share This Page