> From Steven D'Aprano > Sent: Tuesday, December 13, 2016 6:49 PM > To: python-ideas@python.org > Subject: Re: [Python-ideas] Enhancing vars() > > But if the object has __slots__, with or without a __dict__, then vars > should return a proxy which direct reads and writes to the correct slot > or dict. > > It might be helpful to have a slotsproxy object which provides a > dict-like interface to an object with __slots__ but no __dict__, and > build support for both __slots__ and a __dict__ on top of that.
That might be a bit tricky, for example, it's possible that a class has a `foo` slot *and* a `foo` instance attribute (by virtue of subclasses). What would you do in that case? Or what if there's a slot that doesn't have any value (i.e. raises AttributeError on access, but exists on the class nonetheless), but an instance attribute with the same name exists? And so on. > If the objects has *neither* __slots__ nor __dict__, vars can probably > raise a TypeError. Is that even possible in pure Python? The only object I know that can do this is `object`, but some other C objects might do that too. -Emanuel _______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/