pyre-check icon indicating copy to clipboard operation
pyre-check copied to clipboard

Do not warn about "Uninitialized local [61]" if the program calls exit() before using the variable.

Open jp-berg opened this issue 1 year ago • 0 comments

Pyre Feature Request

Is your feature request related to a problem? Please describe.

Pyre seems to lack understanding of the exit()-keyword. If I try to initialize a variable v and exit the program if the initialization fails, I do not want pyrex to complain that v "is undefined, or not always defined." (Uninitialized local [61])

Describe the solution you'd like Pyre should not warn about "Uninitialized local [61]" if the program exits in case the variable is not initialized.

Describe alternatives you've considered -

Additional context

Examples where I would like pyre to not warn about "Uninitialized local [61]" with regards to "v":

try:
    v = initV()
except InitError as e:
    print("Could not initialize v", e, file=sys.stderr)
    exit(ERRORCODE)
return v

if x_is_right_for_v(x):
    v = x
else:
    print(f"{x=} does not work for v")
    exit(ERRORCODE)
do_useful_stuff(v)

I recon that this type of pattern can be common when initializing the Python-application and something goes critically wrong, but I am still inexperienced, so this may be a bad pattern alltogether.

jp-berg avatar May 22 '23 14:05 jp-berg