PyCharm告诉我,在达到return语句之前,某些代码在方法中是无法访问的。我不禁想知道这甚至是遥不可及的?
def post(self):
# get the desired parameters
username = self.request.get('user')
password = self.request.get('pass')
if not self.REGEX.match(username) or not self.REGEX.match(password):
logging.debug('RegistrationHandler: Bad credentials ->', username, password)
self.fail('bad username or password')
print 'Blah' # <---- shows as UNREACHABLE ?
return # <---- shows as UNREACHABLE ?
self.fail
只需拨打self.response.write(things)
。
更新
是的,当我用try / catch子句包围它时,问题就解决了......奇怪。 (请注意,该方法不会总是引发异常。
答案 0 :(得分:8)
我实际上认为这是PyCharm中的一个错误,认为fail
指的是TestCase.fail
,这实际上会使代码无法访问。
如果我使用您的示例,但将fail
重命名为failure
,则错误消失。我会向PyCharm的友好人员报告这个错误,看看实际情况是否如此。
答案 1 :(得分:-1)
此代码无法访问...
检查信息:此检查检测正常无法到达的代码。
随机导入
输入import List, Any
while True:
x: List[Any] = list(str(random.sample(range(1001, 10000), 1)))
x.remove("[")
x.remove("]")
print(x)
答案 2 :(得分:-1)
检查函数的缩进和无法访问的语句/行。
我使用它就像第二个函数包含在第一个函数的缩进中
How the code should be when indentation removed
然后我删除了 if 语句之前的缩进,我得到了结果。 . . . . . . . . 不客气!