Re: ANNOUNCE: Thesaurus - a recursive dictionary subclass usingattributes

Discussion in 'Python' started by Cameron Simpson, Dec 11, 2012.

  1. On 11Dec2012 15:57, Dave Cinege <> wrote:
    | On Tuesday 11 December 2012 01:41:38 Ian Kelly wrote:
    | > running into bugs like this:
    | > >>> thes = Thesaurus()
    | > >>> thes.update = 'now'
    | > >>> thes.update
    | >
    | > <built-in method update of Thesaurus object at 0x01DB30C8>
    |
    | I've noticed this but it's mostly pointless, as meaningful code does work.
    | (Also you stepped on the existing 'update()' dictionary method.)

    I think that was a deliberate choice of name by Ian.

    I've got a class like Thesaurus that subclasses dict and maps attributes
    to dictionary elements (with a few special purpose tweaks I could go into
    if anyone cares). I made a deliberate decision to only map UPPERCASE
    attributes to dict keys to avoid exactly the kind of conflict above,
    because:

    thes.update = 'now'

    must either trash the dict.update method _or_ fail to present .update as
    'now'. Both have their downsides. So at the cost of shoutier but still
    effective code I accepted only .UPPERCASE attribute names as mapping to
    keys.

    This compromise also makes subclassing much easier, because the
    subclasser is free to use conventional lowercase attribute names.

    Cheers,
    --
    Cameron Simpson <>

    Thousands at his bidding speed,
    And post o'er land and ocean without rest - Milton
    Cameron Simpson, Dec 11, 2012
    #1
    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. Jason Friedman
    Replies:
    0
    Views:
    104
    Jason Friedman
    Dec 11, 2012
  2. Ian Kelly
    Replies:
    0
    Views:
    124
    Ian Kelly
    Dec 11, 2012
  3. Dave Cinege
    Replies:
    0
    Views:
    153
    Dave Cinege
    Dec 11, 2012
  4. Ian Kelly
    Replies:
    0
    Views:
    145
    Ian Kelly
    Dec 11, 2012
  5. Ian Kelly
    Replies:
    0
    Views:
    120
    Ian Kelly
    Dec 11, 2012
Loading...

Share This Page