[issue13290] get vars for object with __slots__

2017-04-05 Thread Raymond Hettinger
Raymond Hettinger added the comment: > On any case, feel free to mark this as "rejected" or "wont fix" Okay, will do. And though I think the idea had some significant downsides, it is was creative and we appreciate the suggestion. -- resolution: -> rejected stage: needs patch ->

[issue13290] get vars for object with __slots__

2017-04-05 Thread João Bernardo
João Bernardo added the comment: Being the OP, at that time I felt it was important to have a vars() function that worked on __slots__ to ease something I was developing. The truth for me is: __slots__ is not really relevant anymore. The benefits it brings are not enough to make the feature

[issue13290] get vars for object with __slots__

2017-04-04 Thread Raymond Hettinger
Raymond Hettinger added the comment: I think this API expansion should not be done. As a teacher of Python, I find that vars(o) is easily understood as a short-cut for o.__dict__ in much the same way as len(o) is a short-cut for o.__len__(). The proposed change makes this tool harder to

[issue13290] get vars for object with __slots__

2017-04-04 Thread Jim Fasarakis-Hilliard
Changes by Jim Fasarakis-Hilliard : -- nosy: +Jim Fasarakis-Hilliard ___ Python tracker ___

[issue13290] get vars for object with __slots__

2016-12-13 Thread Terry J. Reedy
Terry J. Reedy added the comment: Michelle (maker)'s patch was reviewed by Serhiy and Richard in msg171867 and following. It appears that stage should be 'needs revised patch'. -- ___ Python tracker

[issue13290] get vars for object with __slots__

2016-12-13 Thread Steven D'Aprano
Steven D'Aprano added the comment: I independently raised this on Python-Ideas and the initial responses are that vars() should support objects with slots too. https://mail.python.org/pipermail/python-ideas/2016-December/043965.html -- nosy: +steven.daprano versions: +Python 3.7

[issue13290] get vars for object with __slots__

2015-03-13 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Oh, this was incorrect example. The correct one is: $ ./python -m timeit -s from http.cookiejar import parse_ns_headers -- parse_ns_headers(['foo=bar; path=/; version=1; Expires=Thu, 01 Jan 1970 00:00:10 GMT']) Before: 1 loops, best of 3: 177 usec per

[issue13290] get vars for object with __slots__

2015-03-13 Thread Serhiy Storchaka
Changes by Serhiy Storchaka storch...@gmail.com: -- Removed message: http://bugs.python.org/msg238021 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13290 ___

[issue13290] get vars for object with __slots__

2012-11-12 Thread Eric Snow
Changes by Eric Snow ericsnowcurren...@gmail.com: -- nosy: +eric.snow ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13290 ___ ___ Python-bugs-list

[issue13290] get vars for object with __slots__

2012-10-06 Thread Michele Orrù
Michele Orrù added the comment: As a reference, linking the discussion on python-dev. http://mail.python.org/pipermail/python-dev/2012-October/122011.html -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13290

[issue13290] get vars for object with __slots__

2012-10-03 Thread Michele Orrù
Michele Orrù added the comment: Patch + unittests + documentation attached. $ ./python -m test -R 3:2 test_builtin [1/1] test_builtin beginning 5 repetitions 12345 . 1 test OK. [158296 refs] -- keywords: +patch nosy: +maker Added file:

[issue13290] get vars for object with __slots__

2012-10-03 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: I added some comments in Rietveld. ReST documentation should be updated too. vars() returns modifiable dict. The patch should be much harder if we want to preserve this behavior. Otherwise, the difference must be explicitly documented. -- nosy:

[issue13290] get vars for object with __slots__

2012-10-03 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: There's another thing. __slots__ value is converted to a tuple and saved as ht_slots field in PyHeapTypeObject. You can use fast PyTuple_GET_ITEM() for item access. -- ___ Python tracker rep...@bugs.python.org

[issue13290] get vars for object with __slots__

2012-10-03 Thread Richard Oudkerk
Richard Oudkerk added the comment: The patch does not seem to walk the mro to look for slots in base classes. Also, an instance with a __dict__ attribute may also have attributes stored in slots. BTW, copyreg._slotnames(cls) properly calculates the slot names for cls and tries to cache them

[issue13290] get vars for object with __slots__

2012-10-03 Thread Michele Orrù
Michele Orrù added the comment: The patch does not seem to walk the mro to look for slots in base classes. Also, an instance with a __dict__ attribute may also have attributes stored in slots. Well, what I am doing is more or less the equivalent of return object.__slots__ if

[issue13290] get vars for object with __slots__

2012-10-03 Thread Richard Oudkerk
Richard Oudkerk added the comment: Well, what I am doing is more or less the equivalent of return object.__slots__ if hasattr(object, '__slots') else object.__dict__ and this is coherent with the updated documentation. The one you proposed is an alternative behavior; am I supposed to

[issue13290] get vars for object with __slots__

2012-10-03 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: The patch does not seem to walk the mro to look for slots in base classes. Also, an instance with a __dict__ attribute may also have attributes stored in slots. BTW, copyreg._slotnames(cls) properly calculates the slot names for cls and tries to cache

[issue13290] get vars for object with __slots__

2012-10-03 Thread Richard Oudkerk
Richard Oudkerk added the comment: This is from Python side. Did ht_slots field of PyHeapTypeObject does not contain properly calculated slot names? Looking at the code, it appears that ht_slots does *not* include inherited slots. -- ___ Python

[issue13290] get vars for object with __slots__

2012-10-03 Thread Terry J. Reedy
Terry J. Reedy added the comment: As I understand it, var(ob) is pretty much a synonym for ob.__dict__. Without knowing the internal details, I think vars should do with slots what it would do if slots were not used and normal dicts were used. In particular, if a class is changed by adding

[issue13290] get vars for object with __slots__

2012-10-03 Thread Richard Oudkerk
Richard Oudkerk added the comment: That modifying the dict has no effect on the object is okay. I have written vars(obj).update(...) before. I don't think it would be okay to break that. -- ___ Python tracker rep...@bugs.python.org

[issue13290] get vars for object with __slots__

2012-10-03 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: I see a special warning in the documentation: Note: The returned dictionary should not be modified: the effects on the corresponding symbol table are undefined. [2] [2] In the current implementation, local variable bindings cannot normally be affected

[issue13290] get vars for object with __slots__

2012-10-03 Thread Richard Oudkerk
Richard Oudkerk added the comment: A search of googlecode shows 42 examples of vars(...).update compared to 3000 for .__dict__.update. I don't know if that is enough to worry about. http://code.google.com/codesearch#search/q=vars\%28[A-Za-z0-9_]%2B\%29\.update%20lang:^python$type=cs

[issue13290] get vars for object with __slots__

2011-11-05 Thread Éric Araujo
Éric Araujo mer...@netwok.org added the comment: You should attach diffs (context diffs, I believe) Nope, these are hard to read :) The universal diff format is the unified one. That’s also what Mercurial uses (see the devguide for more info on contributing). -- nosy: +eric.araujo

[issue13290] get vars for object with __slots__

2011-11-05 Thread Éric Araujo
Changes by Éric Araujo mer...@netwok.org: -- nosy: +rhettinger ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13290 ___ ___ Python-bugs-list

[issue13290] get vars for object with __slots__

2011-11-04 Thread Terry J. Reedy
Terry J. Reedy tjre...@udel.edu added the comment: New features only go in future versions: Given the doc: With a module, class or class instance object as argument (or anything else that has a __dict__ attribute), return that attribute. So you are proposing a change in the definition of

[issue13290] get vars for object with __slots__

2011-11-04 Thread João Bernardo
João Bernardo jbv...@gmail.com added the comment: Oh, sorry for the full file. Yes, I only changed after d = PyObject_GetAttrString(v, __dict__); if (d == NULL) { I was searching for uses of slots other than __slots__ = (a, b) and I saw a guy saying that dicts may have

[issue13290] get vars for object with __slots__

2011-11-04 Thread Terry J. Reedy
Terry J. Reedy tjre...@udel.edu added the comment: PyUnicode_Check may still be correct. I have not examined PEP393 in detail. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13290 ___

[issue13290] get vars for object with __slots__

2011-10-29 Thread João Bernardo
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.