This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author JBernardo
Recipients JBernardo
Date 2011-10-29.07:04:03
SpamBayes Score 1.0589573e-08
Marked as misclassified No
Message-id <1319871850.77.0.869546838833.issue13290@psf.upfronthosting.co.za>
In-reply-to
Content
I just realized the builtin function `vars` can't handle custom objects without the __dict__ attribute.

It would be nice if it worked with objects that have __slots__ to make them look more like normal objects and to make debugging easier.

I changed the source of "Python/bltinmodule.c" to accept this new case, but, as I'm fairly new to the C API, it may not be much good.

I'm attaching the whole file to this Issue and the `builtin_vars` function was modified (lines 1859 to 1921) to work with:
__slots__ = ('a', 'b', 'c')
__slots__ = 'single_name'
__slots__ = {'some': 'mapping'}

The output is a dict (just like in the __dict__ case).

#Example
>>> class C:
       __slots__ = ['x', 'y']

>>> c = C()
>>> c.x = 123
>>> vars(c)
{'x': 123}
History
Date User Action Args
2011-10-29 07:04:12JBernardosetrecipients: + JBernardo
2011-10-29 07:04:10JBernardosetmessageid: <1319871850.77.0.869546838833.issue13290@psf.upfronthosting.co.za>
2011-10-29 07:04:10JBernardolinkissue13290 messages
2011-10-29 07:04:09JBernardocreate