Is it possible to hint PyCharm that method is always raising exception to calm "uninitialized variable" warnings?

With twisted framework and generators-based async coding style it is common to have code like that:

try:
    result = yield some_async_method()
except SomeException:
    defer.returnValue(None)

do_something(result)

PyCharm is correctly pointing that `do_something(result)` might use uninitialized variable `result`. But I know that this is ok since `returnValue` is always raising an exception, so we never get past this try...except with unitialized `result`. Is it possible to give PyCharm a hint about this particular function is never returning and always raising exception?

 

Thanks

2 comments
Comment actions Permalink

Interested in this as well... Any solution?

1
Comment actions Permalink

If you have access to the returnValue source code, then you can return the exception instead of raising it, in which case the resulting change would look like so:

try:
    result = yield some_async_method()
except SomeException:
    raise defer.returnValue(None)

 

Alternatively, you can assert false after returnValue:

try:
    result = yield some_async_method()
except SomeException:
    defer.returnValue(None)
    assert False

0

Please sign in to leave a comment.