Tibibs
Tibibs

Reputation: 91

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')

Upvotes: 0

Views: 4717

Answers (2)

Tibibs
Tibibs

Reputation: 91

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.

Upvotes: 0

Sorin Burghiu
Sorin Burghiu

Reputation: 779

Try to move the functions sub1() and sub2() above the main_test()

Upvotes: 1

Related Questions