Idea: __all__ in classes?

Michael Hudson mwh at python.net
Fri Jan 17 06:32:51 EST 2003


mlh at furu.idi.ntnu.no (Magnus Lie Hetland) writes:

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

As a gut reaction, Heck No.  I'm a fan of cooperative encapsulation.

[snip heresy <wink>]
> With properties and metaclasses this should be fairly easy to
> implement. (The private stuff I've already implemented with properties
> a while back.)

How do you distinguish access from inside the class and access
outside?

> Of course this need not be the default behaviour; a superclass with
> a suitable __metaclass__ attribute would be sufficient...

In which case ...

> 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?

... no.

All IMHO, of course.

Hmm, maybe pychecker could look for this sort of thing, though.  Or
you could issue warnings on "inappropriate" accesses.  Strangely, I
find that idea much more acceptable, and I'm not quite sure why.

Cheers,
M.

-- 
  The bottom tier is what a certain class of wanker would call
  "business objects" ...                      -- Greg Ward, 9 Dec 1999




More information about the Python-list mailing list