I am reading in some data with try, except blocks (to allow for managed shutdown in case of errors), this often causes Pycharm to read variables as "may be referenced before assignment" as it is apparently incapable of working out that they will either have a value or the function will be exited. e.g.
import sys
def program_exit(code):
sys.exit(code)
def read_a(input_value):
try:
a = input_value
except:
program_exit(5)
a += 1 # referenced before assignment warning
return a
I know it is possible to block the warning for a specific line but is there any way to tell pycharm that the variable will be defined so that I don't have to block the warning for all subsequent uses of the variable e.g.
import sys
def program_exit(code):
sys.exit(code)
def read_a(input_value):
try:
a = input_value
except:
program_exit(5)
# Pycharm: has_value(a)
a += 1 # no warning
return a
Thanks