New submission from Jim Jewett <jimjjew...@users.sourceforge.net>:

Copy of issue 5397

In python 3, UserDict (and DictMixin) are gone; presumably they should 
be replaced by either a dict subclass or the ABC MutableMapping.

Unfortunately, there doesn't seem to be a clean way to inherit from 
both.  

In python 2.x, you could write

  class MyDict(DictMixin, dict): ...

but with

  class MyDict(MutableMapping, dict): ...

MutableMapping explicitly overrides __getitem__, __setitem__, and 
__delitem__ to raise a KeyError.

The OrderedDict implementation in issue 5397 puts the concrete class 
first, and then handles composite methods manually, by either rewriting 
them (repr, copy) or explicitly delegating past dict and straight to 
MutableMapping (setdefault, update, etc.)

Both solutions seem fragile.  

Unfortunately, the closest I come to a solution is to split the ABC 
into a Mixin portion and an ABC enforcer.

    # The concrete methods of the current ABC
    class MapMixin: 

    # The abstract methods that get checked
    class MutableMapping(MapMixin):

# Trust that dict will always implement 
# all required concrete methods for us
class MyDict(MapMixin, dict):

----------
components: Library (Lib)
messages: 82999
nosy: aronacher, georg.brandl, jimjjewett, pitrou, rhettinger
severity: normal
status: open
title: MutableMapping code smell (see OrderedDict)
versions: Python 3.1

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue5402>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to