Commit de7ce2a
Error on re-annotating global identifiers
Summary:
This diff adds illegal annotation target errors when trying to re-annotate an already annotated global.
On master, we already error for a re-annotation of a local:
```
def foo() -> None:
x: int = 1
x: str # error is on this line
x = ""
return
```
Illegal annotation target [35]: Target `x` cannot be annotated after it is first declared.
But we don't do this for re-annotation of a global:
```
constant: int = 1
def foo() -> None:
global constant
constant: str # no error
```
And instead relied on the fact that we were special casing out any assignments that touch globals from changing the local annotation map.
In this case, we should be throwing the same error on re-annotation of an already declared global, which would be a lot more user friendly than silently letting the re-annotation pass without actually changing the type, then only erroring if we try to assign a value later.
Reviewed By: grievejia
Differential Revision: D30404490
fbshipit-source-id: 21cb9beb60bb651cb5fa36c6e96a964bfdfa80ed1 parent 5e999e0 commit de7ce2a
File tree
2 files changed
+13
-5
lines changed- source/analysis
- test/integration
2 files changed
+13
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
743 | 743 | | |
744 | 744 | | |
745 | 745 | | |
746 | | - | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
747 | 750 | | |
748 | 751 | | |
749 | 752 | | |
| |||
815 | 818 | | |
816 | 819 | | |
817 | 820 | | |
818 | | - | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
819 | 826 | | |
820 | 827 | | |
821 | 828 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4477 | 4477 | | |
4478 | 4478 | | |
4479 | 4479 | | |
4480 | | - | |
| 4480 | + | |
4481 | 4481 | | |
4482 | 4482 | | |
4483 | | - | |
| 4483 | + | |
4484 | 4484 | | |
4485 | 4485 | | |
4486 | 4486 | | |
| |||
4492 | 4492 | | |
4493 | 4493 | | |
4494 | 4494 | | |
4495 | | - | |
| 4495 | + | |
| 4496 | + | |
4496 | 4497 | | |
4497 | 4498 | | |
4498 | 4499 | | |
| |||
0 commit comments