Search code examples
pythonpython-3.xdjangopylance

Pylance, functions not defined


I have a simple code with 3 functions. the first one get some values from the 2 others to check some conditions, but I get an error from Pylance saying the functions sub1 and sub2 are not defined. any clues?

@staticmethod
def main_test():
    var1 = sub1()
    if not var1:
        return ('test1 not even')
    var2 = sub2()
    if not var2:
        return ('test2 not even')
    return True

@staticmethod
def sub1():
    test = random.randint(1, 10)
    if (test % 2)==0:
        return True
    return ( str(test) + 'is Odd')

@staticmethod
def sub2():
    test = random.randint(1, 10)
    if (test % 2)==0:
        return True
    return ( str(test) + 'is Odd')

Solution

  • I found the problem. my functions were inside a class and to call them I add to specify the class name

    class_name.sub1()
    

    My code is a bit long and I didn't have in mind the class at all.