[Python-projects] Type inference not working?

Sylvain Thénault sylvain.thenault at logilab.fr
Wed Jan 23 19:09:22 CET 2008


On Wed, Jan 23, 2008 at 06:48:22PM +0100, Maarten ter Huurne wrote:
> I wrote on 2008-01-23 06:27:07 PM:
> 
> [Lotus Notes ate my whitespace, here is the proper code layout, I hope]
> 
> > ===
> > class SomeClass(object):
> >
> >     def __m(self):
> >         pass
> >
> >     SomeClass().__m()
> > ===

huum, I'm not sure about what you're trying to acheive and what
behaviour you would expect. Here is an exemple of what's ok and what's
not (using a private static method since this is the worst case, but it
could be a class/instance method as well) ::

class SomeClass(object):

    @staticmethod
    def __m():
        pass

    def method(self):
        # calling private method within the class is ok
        self.__m()

    @classmethod
    def clsmethod(cls):
        # calling private method within the class is ok
        cls.__m()

    @staticmethod
    def statmethod():
        # calling private method within the class is ok
        SomeClass.__m()

class AnotherClass(object):
    @staticmethod
    def statmethod():
        # calling private method from another class is not ok
        SomeClass.__m()
     
# calling private method on an instance is not ok, and that's right
SomeClass().__m()


Executing pylint on this produce ::

  W0212: 26:AnotherClass.statmethod: Access to a protected member __m of a
  client class
  W0212: 29: Access to a protected member __m of a client class

which is what was expected (for me at least ;)
Hope that helps
-- 
Sylvain Thénault                               LOGILAB, Paris (France)
Formations Python, Zope, Plone, Debian:  http://www.logilab.fr/formations
Développement logiciel sur mesure:       http://www.logilab.fr/services
Python et calcul scientifique:           http://www.logilab.fr/science



More information about the Python-Projects mailing list