Re: Correct type for a simple “bag of attributes” namespace object

Chris Angelico rosuav at gmail.com
Sun Aug 3 09:35:18 EDT 2014


On Sun, Aug 3, 2014 at 11:25 PM, Roy Smith <roy at panix.com> wrote:
> in which case, I've said, "make Foos just like objects, except for, oh,
> never mind, there aren't any differences".  But, in reality, the system
> bolted on the ability to have user-defined attributes without telling
> me.  I don't think it's unreasonable to be surprised at that.

I agree that this is slightly surprising. However, imagine if it were
the other way:

class Foo(object):
    x = 1
    def __init__(self): self.y = 2

These would throw errors, unless you explicitly disable __slots__
processing. When there's two ways to do things and both would be
surprising, you pick the one that's going to be less of a surprise, or
surprising less often, and accept it. That doesn't mean it's not a
problem, but it's better than the alternative.

ChrisA



More information about the Python-list mailing list