python - PyCharm:无法访问的代码?

标签 python google-app-engine pycharm

PyCharm 向我显示,在到达返回语句之前,方法中的某些代码无法访问。我不禁想知道这怎么可能呢?

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 子句包围它时,问题就解决了……奇怪。 (请注意,该方法并不总是引发异常。

最佳答案

其实我认为这是PyCharm的一个bug,认为fail指的是TestCase.fail ,这实际上会使代码无法访问。

如果我使用您的示例,但将 fail 重命名为例如 failure,错误就会消失。我会向 PyCharm 的友好人员报告此错误,看看是否确实如此。

关于python - PyCharm:无法访问的代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21954959/

相关文章:

使用 D 代替 E 的 Python 科学记数法

python - 如何更改我的构建配置,以便 cmd 指向 python 解释器的实际位置?

http - GAE Go http 发布链接

python - GAE : Model loses track of parent->child relationship

Python:装饰器、作用域和模块导入

google-app-engine - App Engine 开发服务器编码

vim - 更改 i3wm 工作区时 Pycharm "writing cursor"消失

python - 如何在别人的 Windows 机器上的虚拟环境中本地运行 python 脚本并使其始终工作?

node.js - Pycharm 与 Electron - runnerw.exe : CreateProcess failed with error 193: %1 is not a valid Win32 application

python - 通过 HTTP 服务日志