New submission from João Bernardo <jbv...@gmail.com>:

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}

----------
components: Interpreter Core
files: bltinmodule.c
messages: 146598
nosy: JBernardo
priority: normal
severity: normal
status: open
title: get vars for object with __slots__
type: feature request
versions: Python 3.2, Python 3.3
Added file: http://bugs.python.org/file23546/bltinmodule.c

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue13290>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to