Will python never intend to support private, protected and public?

en.karpachov at ospaz.ru en.karpachov at ospaz.ru
Thu Sep 29 23:53:13 EDT 2005


On Thu, 29 Sep 2005 16:59:01 +0200
Fredrik Lundh wrote:

> as long as you don't cheat, that is:
> 
> # your code
> 
> class Secret:
>     def __init__(self):
>         self.__hidden = "very secret value"
> 
> # my code
> 
> from yourcode import Secret
> 
> class Secret(Secret):
>     def gethidden(self):
>         return self.__hidden

It's not a cheat, it's an accident you have no protection against.

Consider:

class Secret(NotSoSecret):
     # pass

Looks like you must know every one of the base classes of the NotSoSecret,
whether there is some base class named Secret? And, if so, you must also
know these classes _implementation_, every one of their attributes,
variables and methods, to avoid accidental overriding?

For me, it's not what inheritance is about. This accident should be rare,
but possible.

-- 
jk



More information about the Python-list mailing list