[Python-ideas] One obvious way to do interning [Was: Retrieve an arbitrary element from a set without removing it]
g.brandl at gmx.net
Mon Oct 26 18:37:16 CET 2009
Alexander Belopolsky schrieb:
> Changing the subject to reflect branched discussion and forwarding to
> python-ideas where it probably belongs.
> On Mon, Oct 26, 2009 at 12:02 PM, Terry Reedy <tjreedy at udel.edu> wrote:
>> Alexander Belopolsky wrote:
>>> Here is an alternative idea on how storing interned objects in a set
>>> can be supported. Currently set.add method returns None and has no
>>> effect when set already has an object equal to the one being added. I
>>> propose to consider changing that behavior to make set.add return the
>>> added object or the set member that is equal to the object being
>>> added. It is unlikely that many programs rely on the return value
>>> being None (with doctests being a probable exception), so adding this
>>> feature is unlikely to cause much grief.
>> I had exactly the same idea, but did not post because it violates the
>> general rule that mutators return None.
> Is there such a rule? What about set/dict pop?
The rule is about methods that do not have an obvious return value, where
the choice is between returning self and None.
Thus spake the Lord: Thou shalt indent with four spaces. No more, no less.
Four shall be the number of spaces thou shalt indent, and the number of thy
indenting shall be four. Eight shalt thou not indent, nor either indent thou
two, excepting that thou then proceed to four. Tabs are right out.
More information about the Python-ideas