PyCharm is showing me that some code is unreachable within a method before the return statement is reached. I cannot help but wonder how is that even remotely possible?
JavaScript
x
12
12
1
def post(self):
2
# get the desired parameters
3
username = self.request.get('user')
4
password = self.request.get('pass')
5
6
if not self.REGEX.match(username) or not self.REGEX.match(password):
7
logging.debug('RegistrationHandler: Bad credentials ->', username, password)
8
self.fail('bad username or password')
9
10
print 'Blah' # <---- shows as UNREACHABLE ?
11
return # <---- shows as UNREACHABLE ?
12
self.fail
simply calls self.response.write(things)
.
Update:
Yeah, when I surround it with a try/catch clause, the issue is resolved… Strange. (Note that the method doesn’t always raise an exception.
Advertisement
Answer
I actually think this is a bug in PyCharm, thinking that fail
refers to TestCase.fail
, which would in fact make the code unreachable.
If I use your example, but rename fail
to for example failure
, the errors disappears. I’d report this bug to the friendly folks at PyCharm to see if this is in fact the case.