Pylint false positives

Frank Millman frank at chagford.com
Tue Aug 14 04:58:17 EDT 2018


"D'Arcy Cain"  wrote in message 
news:865ed61a-cf1d-959f-f77e-dc586fe6e0cf at VybeNetworks.com...
>
> On 2018-08-14 03:38 AM, Frank Millman wrote:
> > Hi all
> >
> > Pylint is flagging a lot of lines as errors that I would consider to be
> > acceptable.
> >
> > I have an abstract class ClassA with a number of concrete sub-classes.
> > ClassA has a method which invokes 'self.method_b()' which is defined
> > separately on each sub-class. Pylint complains that "Instance of
> > 'ClassA' has no  'method_b' member".
> >
> > First question - as a matter of style, is Pylint correct? If so, I could
> > define 'method_b' in ClassA and raise NotImplementedError. Is this
> > considered more pythonic? The downside is that I have quite a few of
> > them, so it would add some clutter.
>
> I would add the method.  It's one line:
>
>   def method_b(self): raise NotImplementedError
>
> When you say that you have quite a lot of them, what is "them"?  Many
> master classes or many methods in the class?  If the latter, one line
> each isn't so bad.  If the former I wonder if a master, master class is
> called for.
>

I do mean a lot of methods, not classes. I don't have any problem adding the 
lines. It is just that, before I starting using pylint, it had not occurred 
to me that there was any problem with my approach. If an experienced python 
programmer was reviewing my code, would they flag it as 'bad style'?

> I am also getting a funny smell from your description.  Are you sure
> that you need to redefine the methods?  Perhaps you just need to define
> some class variables and use one method.  You can also define your own
> method and call the classA method inside it for common functionality.
>

As an example, I have a master class defining a unit of data (i.e. the value 
of a column) retrieved from a database. I have separate sub-classes for each 
data type - text, integer, date, etc. To ensure that a value is valid before 
storing it as an instance attribute, I call a method called 'check_value'. 
The details of check_value vary according to the data type, but that is 
transparent to the piece of code that calls check_value().

Frank





More information about the Python-list mailing list