[Python-ideas] Enhancing vars()

Steve Dower steve.dower at python.org
Mon Dec 12 23:02:28 EST 2016


I'm +1. This bites me far too often.

> in the past developers
were encouraged to put only "useful" attributes in __dir__.

Good. If I'm getting vars() I really only want the useful ones. If I need interesting/secret ones then I'll getattr for them.

Cheers,
Steve

Top-posted from my Windows Phone

-----Original Message-----
From: "Alexander Belopolsky" <alexander.belopolsky at gmail.com>
Sent: ‎12/‎12/‎2016 19:47
To: "Steven D'Aprano" <steve at pearwood.info>
Cc: "python-ideas" <python-ideas at python.org>
Subject: Re: [Python-ideas] Enhancing vars()



On Mon, Dec 12, 2016 at 6:45 PM, Steven D'Aprano <steve at pearwood.info> wrote:

Proposal: enhance vars() to return a proxy to the object namespace,
regardless of whether said namespace is __dict__ itself, or a number of
__slots__, or both.

How do you propose dealing with classes defined in C?  Their objects don't have __slots__.


One possibility is to use __dir__ or dir(), but those can return anything and in the past developers
were encouraged to put only "useful" attributes in __dir__.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20161212/fdee7ac7/attachment-0001.html>


More information about the Python-ideas mailing list