Re: [Python-ideas] __vars__ special method

2018-01-25 Thread Yahya Abou 'Imran via Python-ideas
> I think you may have misunderstood the purpose of vars(). It isn't to be > a slightly different version of dir(), instead vars() should return the > object's namespace. Not a copy of the namespace, but the actual > namespace used by the object. > > This is how vars() currently works: > > py> clas

Re: [Python-ideas] __vars__ special method

2018-01-22 Thread Steven D'Aprano
On Mon, Jan 22, 2018 at 09:20:16AM -0500, Yahya Abou 'Imran via Python-ideas wrote: > On top of this old proposition: > https://bugs.python.org/issue13290 > > We could have a __vars__ method that would be called by vars() if defined. > The use cases: > > 1. let vars() work with instances without

[Python-ideas] __vars__ special method

2018-01-22 Thread Yahya Abou 'Imran via Python-ideas
On top of this old proposition: https://bugs.python.org/issue13290 We could have a __vars__ method that would be called by vars() if defined. The use cases: 1. let vars() work with instances without __dict__; 2. hide some attributes from the public API. Example for 1: class C: __slots__