Skip to content Skip to sidebar Skip to footer

Pylint Rules : How To Solve Undefined Variable?

I get some message from pylint rules : from scrapy.spiders import Spider class MySpider(Spider): #Undefined variable 'Spider' name = 'get' start_urls = ['']

Solution 1:

It seems that there is a bug in pytest I ran the following tests with tox:

[tox]
skipsdist = True
envlist = py{27,34}-pylint{141,142,143,144,145}

[testenv]
whitelist_externals = pylint
deps =
  pylint141: pylint==1.4.1
  pylint142: pylint==1.4.2
  pylint143: pylint==1.4.3
  pylint144: pylint==1.4.4
  pylint145: pylint==1.4.5
commands = pylint -r n test.py

on the following file

"""Custom exceptions"""

class MyException(Exception):
    """My custom exception"""

    def __init__(self, message):
        super(MyException, self).__init__(message)

I obtain the following result:

ERROR:   py27-pylint141: commands failed
ERROR:   py27-pylint142: commands failed
ERROR:   py27-pylint143: commands failed
ERROR:   py27-pylint144: commands failed
  py27-pylint145: commands succeeded
ERROR:   py34-pylint141: commands failed
ERROR:   py34-pylint142: commands failed
ERROR:   py34-pylint143: commands failed
ERROR:   py34-pylint144: commands failed
  py34-pylint145: commands succeeded

With those errors:

************* Module test
E:  7,27: Undefined variable 'self' (undefined-variable)
E:  7,42: Undefined variable 'message' (undefined-variable)

Assuming this, the best way is to move to at least the version 1.4.5 of pylint.


Solution 2:

You do not have to declare variables in Python. And your class definition is wrong. In Python you dont need parameters and brackets for it. Class Definition Syntax

class MySpider: 
    #your code here

Post a Comment for "Pylint Rules : How To Solve Undefined Variable?"