我今天刚开始使用PyCharm Community Edition 2016.3.2.每次我从我的函数中分配一个值时at_square,它都会警告我'函数at_square不会返回任何内容',但它肯定会在每个实例中执行,除非在执行期间引发错误,并且函数的每次使用都按预期运行.我想知道为什么PyCharm认为它没有,以及我能做些什么来纠正它.(我知道有一个选项可以禁止该特定函数的警告,但是它通过在函数上方的代码中插入一条注释行来实现,并且我觉得必须记住最后将它取出来也很烦人该项目.)
这是有问题的功能:
def at_square(self, square):
""" Return the value at the given square """
if type(square) == str:
file, rank = Board.tup_from_an(square)
elif type(square) == tuple:
file, rank = square
else:
raise ValueError("Expected tuple or AN str, got " + str(type(square)))
if not 0 <= file <= 7:
raise ValueError("File out of range: " + str(file))
if not 0 <= rank <= 7:
raise ValueError("Rank out of range: " + str(rank))
return self.board[file][rank] …Run Code Online (Sandbox Code Playgroud)