The language reference mentions this restriction:
Names defined in annotation scopes cannot be rebound with nonlocal statements in inner scopes. This includes only type parameters, as no other syntactic elements that can appear within annotation scopes can introduce new names.
I noticed that Pyright doesn't implement this restriction, while Mypy does.
def f[Ty](x: Ty) -> Ty:
nonlocal Ty
y: Ty = x
Ty: int = 0
return y
[Pyright Playground] [Mypy Playground]