Inheritance and name clashes

Steve Howell showell30 at yahoo.com
Sun Oct 3 21:00:07 EDT 2010


On Oct 3, 5:17 pm, MRAB <pyt... at mrabarnett.plus.com> wrote:
> On 04/10/2010 00:06, Steve Howell wrote:> On Oct 3, 3:57 pm, Gregory Ewing<greg.ew... at canterbury.ac.nz>  wrote:
> >> Rock wrote:
> >>> What if the
> >>> library I'm using doesn't realase the source, or what if I just can't
> >>> get my hands on it for some reason or another?
>
> >> You can always use dir() on an instance of the class to
> >> find out what names it's using.
>
> > Indeed but the OP should be aware that dir() only reflects the current
> > state of the object.
>
> Could something like pyflakes tell you what private attributes there
> are, basically looking for self._foo or whatever?

Using pyflakes has the same problem as dir().  It can always be
thwarted by the dynamic nature of the language.

I think it's more worthwhile to educate Python newbies on how to
choose libraries.  Well-written libraries can often have tremendous
reuse without the need for subclassing in the first place, by allowing
for callbacks or rich configuration.  Libraries that choose
subclassing as their primary extension mechanism should be selected by
how well they hide their own internal state and by how well they
provide a mechanism to store state in the subclasses.  There are lots
of techniques for library writers to employ here--naming conventions,
delegation, readable documentation, APIs for the subclass to call back
to, etc.







More information about the Python-list mailing list