def f(): a: int print(a) # raises UnboundLocalError # Commenting out the a: int makes it a NameError.