Title: vars() no longer has a useful __repr__
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.1, Python 3.2
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: ezio.melotti Nosy List: daniel.urban, dstanek, eric.araujo, ezio.melotti, rhettinger
Priority: normal Keywords: patch

Created on 2009-03-28 17:08 by rhettinger, last changed 2010-12-18 15:11 by ezio.melotti. This issue is now closed.

File name Uploaded Description Edit
5587.patch dstanek, 2010-08-04 11:25
issue5587.diff daniel.urban, 2010-12-05 15:33
issue5587b.diff daniel.urban, 2010-12-07 04:52 Patch + test (py3k branch)
Messages (9)
msg84315 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2009-03-28 17:08
The vars() builtin now returns a hard to view object.  Formerly, it had
a useful __repr__.

Python 3.1a1 
>>> class A: pass
>>> vars(A)
<dict_proxy object at 0x0131FE70>

IDLE 2.6.1      
>>> class A: pass
>>> vars(A)
{'__module__': '__main__', '__doc__': None}
msg109998 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2010-07-11 12:00
Note that 2.7 output is the same as for 2.6.
msg112789 - (view) Author: David Stanek (dstanek) Date: 2010-08-04 11:25
A possible fix is to add a __repr__ implementation to proxydict. I've attached a patch and also posted it to:
msg123424 - (view) Author: Daniel Urban (daniel.urban) * (Python triager) Date: 2010-12-05 15:33
Based on David Stanek's patch I've made a patch against the current py3k branch. The only difference is, that dict_proxy.__repr__ instead of simply returning the repr of the dict, returns approximately "dict_proxy({!r})".format(self.dict).
msg123425 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2010-12-05 15:40
Thanks for the patch! Can you include also a test that verifies that the repr is printed correctly?
(You can take a look at #7310 if you want to see a possible approach.)
msg123426 - (view) Author: Daniel Urban (daniel.urban) * (Python triager) Date: 2010-12-05 15:53
> Thanks for the patch! Can you include also a test that verifies
> that the repr is printed correctly?

Sure. Where should I put the test? I didn't found any dict_proxy tests, except in ("# Classes don't allow __dict__ assignment and have readonly dicts").
msg123522 - (view) Author: Daniel Urban (daniel.urban) * (Python triager) Date: 2010-12-07 04:52
Okay, I found it :-) Here is a new patch, now with a test.
msg123546 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-12-07 12:41
Looks good to me.
msg124285 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2010-12-18 15:11
Fixed in 3.2 (r87368) and 3.1 (r87370), thanks for the patch!
Date User Action Args
2010-12-18 15:11:39ezio.melottisetstatus: open -> closed
nosy: rhettinger, dstanek, ezio.melotti, eric.araujo, daniel.urban
messages: + msg124285

assignee: ezio.melotti
resolution: fixed
stage: needs patch -> resolved
2010-12-07 12:41:04eric.araujosetmessages: + msg123546
2010-12-07 04:52:31daniel.urbansetfiles: + issue5587b.diff

messages: + msg123522
2010-12-05 18:27:27eric.araujosetnosy: + eric.araujo, - BreamoreBoy
2010-12-05 15:53:57daniel.urbansetmessages: + msg123426
2010-12-05 15:40:17ezio.melottisetmessages: + msg123425
2010-12-05 15:33:21daniel.urbansetfiles: + issue5587.diff
nosy: + daniel.urban
messages: + msg123424

2010-08-04 11:25:46dstaneksetfiles: + 5587.patch

nosy: + dstanek
messages: + msg112789

keywords: + patch
2010-07-11 12:00:39BreamoreBoysetnosy: + BreamoreBoy

messages: + msg109998
stage: test needed -> needs patch
2010-01-15 12:16:37ezio.melottisetversions: + Python 3.2, - Python 3.0
nosy: + ezio.melotti

priority: normal
type: behavior
stage: test needed
2009-04-24 23:51:53rhettingersettitle: vars() no longer has a use __repr__ -> vars() no longer has a useful __repr__
2009-03-28 17:08:39rhettingercreate