Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #34657 > unrolled thread

Re: ANNOUNCE: Thesaurus - a recursive dictionary subclass using attributes

Started byCameron Simpson <cs@zip.com.au>
First post2012-12-12 09:31 +1100
Last post2012-12-12 09:31 +1100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: ANNOUNCE: Thesaurus - a recursive dictionary subclass using attributes Cameron Simpson <cs@zip.com.au> - 2012-12-12 09:31 +1100

#34657 — Re: ANNOUNCE: Thesaurus - a recursive dictionary subclass using attributes

FromCameron Simpson <cs@zip.com.au>
Date2012-12-12 09:31 +1100
SubjectRe: ANNOUNCE: Thesaurus - a recursive dictionary subclass using attributes
Message-ID<mailman.750.1355265569.29569.python-list@python.org>
On 11Dec2012 15:57, Dave Cinege <dave@linkscape.net> 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 <cs@zip.com.au>

Thousands at his bidding speed,
And post o'er land and ocean without rest       - Milton

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web