What does this PyChecker warning mean?

L

Leo Breebaart

When fed the following code:

def Foo():

class A(object):
def __init__(self):
pass

class B(object):
def __init__(self):
pass

PyChecker 0.8.18 warns:

foo.py:9: Redefining attribute (__init__) original line (5)

I do not understand what is meant by this warning. In fact, it
simply seems wrong -- but I have learned not to jump to that
conclusion too quickly, so I was hoping someone here could
perhaps enlighten me...

Many thanks in advance,
 
P

Peter Otten

Leo said:
When fed the following code:

def Foo():

class A(object):
def __init__(self):
pass

class B(object):
def __init__(self):
pass

PyChecker 0.8.18 warns:

foo.py:9: Redefining attribute (__init__) original line (5)

I do not understand what is meant by this warning. In fact, it
simply seems wrong -- but I have learned not to jump to that
conclusion too quickly, so I was hoping someone here could
perhaps enlighten me...

You are right, that's a false positive. pychecker seems to confuse the
namespaces.

Peter
 
S

Steven W. Orr

On 1 June 2010 21:48, Leo Breebaart <[email protected]


When fed the following code:

def Foo():

class A(object):
def __init__(self):
pass

class B(object):
def __init__(self):
pass

PyChecker 0.8.18 warns:

foo.py:9: Redefining attribute (__init__) original line (5)


Out of curiosity, why are you defining two classes inside a function?

-Xav

In terms of constructing a minimal example, Foo might be fodder for a closure
that either returns A or B. Just s stab in the dark...


--
Time flies like the wind. Fruit flies like a banana. Stranger things have .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net
 
L

Leo Breebaart

Not my code! Not my code! :)

This code was contributed by someone else, and I merely took my
default action (in such cases) of running pyflakes, pychecker,
and pylint on it before doing anything else, just to see what
comes up.

As far as I can tell the sole reason for that code being
structured the way it is, is to provide a kind of
module-within-a-module and not clutter up the outer module with
these helper classes needed only by the foo() function.
 
T

Terry Reedy

You are right, that's a false positive. pychecker seems to confuse the
namespaces.

Consider sending this example back to the pychecker author.
The program does not seem to be interpreting the nested class statements
properly.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,828
Latest member
LauraCastr

Latest Threads

Top