[Python-projects] Type inference not working?
Maarten ter Huurne
maarten.ter.huurne at philips.com
Wed Jan 23 20:01:33 CET 2008
Aurélien Campéas <aurelien.campeas at logilab.fr> wrote on 2008-01-23 06:45:11
PM:
> 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()
> > > ===
> >
>
> Hi Marteen,
>
> did you actually execute that code ?
I executed an earlier version, but then I simplified it a bit more and
forgot to execute it again... :(
This is the earlier version, it executes correctly and it triggers the same
warning:
===
class SomeClass(object):
def __m(self):
pass
@staticmethod
def s():
SomeClass().__m()
SomeClass.s()
===
The way I want to use it is by having a factory method like this:
===
@staticmethod
def create(data):
instance = SomeClass()
instance.__setSomething(data)
return instance
===
I want to have several ways of instantiating the same class and doing it
all using different constructor arguments would be messy.
syt at logilab.fr wrote on 2008-01-23 07:09:22 PM:
> 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 ;)
What I'd like to do is call a private instance method from a static method
in the same class. This is flagged as a warning, which could mean:
- PyLint considers this as something that is not OK (why?)
- PyLint doesn't know that the instance is of the same class that the
static method belongs to (my guess)
Bye,
Maarten
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.logilab.org/pipermail/python-projects/attachments/20080123/43e7213a/attachment.htm
More information about the Python-Projects
mailing list