Idea: __all__ in classes?

Magnus Lie Hetland mlh at furu.idi.ntnu.no
Thu Jan 16 20:56:59 CET 2003


I just had an idea: Perhaps the following could be a useful convention
for private attributes (and methods)?

>>> class Foo:
...     __all__ = 'bar', 'baz'
...     bar = 42
...     frozz = 51
...     def baz(self):
...         return 42
>>> f = Foo()
>>> f.bar
42
>>> f.baz()
42
>>> f.frozz
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
AttributeError: Foo attribute 'frozz' is private

With properties and metaclasses this should be fairly easy to
implement. (The private stuff I've already implemented with properties
a while back.) Of course this need not be the default behaviour; a
superclass with a suitable __metaclass__ attribute would be
sufficient...

I guess my question is whether this seems like a good idea at all...
And if it, perhaps, should be proposed as a PEP for inclusion in the
standard libs or something?

Just a thought...

-- 
Magnus Lie Hetland
http://hetland.org




More information about the Python-list mailing list