Function Returning a NoneType in Python?

In the case where sCheck == True is false, you don't return anything. And in Python, a function that doesn't explicitly return anything returns None.

If you were trying to recursively call yourself and return the result, you wanted this:

return falseChecker(binList, r, c, size)

The recursive line:

falseChecker(binList, r, c, size)

needs to be

return falseChecker(binList, r, c, size)

or the recursed function ends, and the outer function keeps going since it hasn't returned yet. It then finishes without returning, and so returns None.


You need a return at the end of falseChecker:

def falseChecker(binList, r, c, size):
    sCheck = isSpaceFree(binList, r, c, size)
    if sCheck == True:
        for x in range(c, c+size):
            for y in range(r, r+size):
                binList[x][y] = size
        return binList
    else:
        c += 1
        if c > len(binList):
            c = 0
            r += 1
            if r > len(binList):
                 return binList

        #################################
        return falseChecker(binList, r, c, size)
        #################################

In Python, functions return None by default if they come to the end of themselves without returning. Furthermore, when falseChecker is run for the first time, if sCheck is False, then it will execute the else block. This code block doesn't contain a return. Because of this, the ultimate return value of falseChecker will be None.