Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!news.linkpendium.com!news.linkpendium.com!panix!roy From: Roy Smith Newsgroups: comp.lang.python Subject: Re: Correct type for a simple “bag of attributes” namespace object Date: Sun, 03 Aug 2014 09:25:53 -0400 Organization: PANIX Public Access Internet and UNIX, NYC Lines: 42 Message-ID: References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> <87r40zmkhr.fsf@elektro.pacujo.net> <53dd0717$0$29973$c3e8da3$5496439d@news.astraweb.com> <857g2qd5oc.fsf_-_@benfinney.id.au> NNTP-Posting-Host: localhost X-Trace: reader1.panix.com 1407072354 4618 127.0.0.1 (3 Aug 2014 13:25:54 GMT) X-Complaints-To: abuse@panix.com NNTP-Posting-Date: Sun, 3 Aug 2014 13:25:54 +0000 (UTC) User-Agent: MT-NewsWatcher/3.5.3b3 (Intel Mac OS X) Xref: csiph.com comp.lang.python:75595 In article , Chris Angelico wrote: > On Sun, Aug 3, 2014 at 10:40 PM, Roy Smith wrote: > > I usually just do: > > > > class Data: > > pass > > my_obj = Data() > > > > That's all you really need. It's annoying that you can't just do: > > > > my_obj = object() > > > > which would be even simpler, because (for reasons I don't understand), > > you can't create new attributes on my_obj. > > [...] > The only reason I can think of for expecting a > basic object to work this way is because of the parallel with > ECMAScript; it's not a fundamental part of the type hierarchy. I don't know about that. I agree that your explanation about object size makes sense for why it wasn't built to work that way, but I don't think the expectation should be surprising. When I write: class Foo(Bar): # stuff I'm saying, "make Foos be just like Bars, except for this stuff". I can do: >>> class Foo(object): ... pass ... >>> f = Foo() >>> f.x = 1 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.