Question

I have this section in my code:

 class CSVFile():                                                                

     # Keys in kwargs that are not allowed                                       
     __black_list = ()                                                           

     def __init__(self, **kwargs):                                               
         for (k, v) in kwargs.iteritems():                                       
             if k in self.__class__.__black_list:                                
                 LOG.error("%s is not allowed ", k)                              
             setattr(self, k, v) 

As you can see I'm assigning key=>value pairs as instance variables. Later on in the code I'm using the variables I set here (ex. self.dest).

And when I check it with pylint it complains :

E: 54,32:CSVFile.upload_file_to_s3: Instance of 'CSVFile' has no 'dest' member

Obviously if I would define self.dest in __init__ method, then this error would go away.

So the question is: Is this code looks "bad" from PEP8 perspective?

Was it helpful?

Solution

In relationship to your code, the only potential violation that I see is the formatting of your key values from **kwargs. As long as **kwargs elements follow PEP 8 variable naming conventions (all_lowercase_words_separted_by_underscores) you should be fine.

The reason that PyLint is complaining at you is that it can't tell that a CSVFile object is going to have a dest attribute (or any other attribute for that matter since they are appended dynamically).

The overall issue is that PyLint does PEP8 checking, but it does other stuff too. This message is part of that 'other stuff'.

Cheers.

OTHER TIPS

There's nothing wrong with what you are doing.

Remember, pylint is a tool (and a great tool that is), but certainly not the goal.

You should keep using pylint, but at times it becomes a nuisance, you can customize the checks you want to run. In this case, you want to disable that particular check.

See the answers to this question, which explain how to customize it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top