[Python-projects] pylint reports about common code to refactor

Duncan Gibson duncan at thermal.esa.int
Thu Aug 3 16:49:59 CEST 2006


After tidying up some application code, I could see that I had some
common code in different classes within one file, but I was surprised
when pylint didn't recognise it. I created the example code below
to help investigate further.

1. If you save the code as a single file, example.py, and run pylint
on it, you won't get any reports of similar lines.

2. If you save the code into two files, functions.py and classes.py,
pylint still won't give any reports about similar lines.

3. If you then run pylint on all three files, pylint only gives
reports about the similar functions in example.py and functions.py.

In all three cases, no report is made about the similar code in
the output method within the classes.

Is there any reason why similar code within a file is not reported,
and why similar code within classes appears to be ignored?

Cheers
Duncan



def one(i):
    print 'Unique header - one'
    i2 = i * i
    i3 = i * i2
    i3 = i * i3
    print i, i2, i3


def two(i):
    print 'Unique header - two'
    i2 = i * i
    i3 = i * i2
    i3 = i * i3
    print i, i2, i3


def three(i):
    print 'Unique header - three'
    i2 = i * i
    i3 = i * i2
    i3 = i * i3
    print i, i2, i3


class One(object):

    def __init__(self, i):
        self._value = i

    def output(self):
        print 'Unique header - One'
        i = self._value
        i2 = i * i
        i3 = i * i2
        i3 = i * i3
        print i, i2, i3
    

class Two(object):

    def __init__(self, i):
        self._value = i

    def output(self):
        print 'Unique header - Two'
        i = self._value
        i2 = i * i
        i3 = i * i2
        i3 = i * i3
        print i, i2, i3
    

class Three(object):

    def __init__(self, i):
        self._value = i

    def output(self):
        print 'Unique header - Three'
        i = self._value
        i2 = i * i
        i3 = i * i2
        i3 = i * i3
        print i, i2, i3
    


More information about the Python-Projects mailing list