-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added check for importing a
Final
variable from another module and …
…then attempting to overwrite it. This partially addresses microsoft/pylance-release#6455. Added check for an attempt to assign to a module-local variable if it is shadowing a `Final` variable declared by the builtins module or some other chained file. This addresses microsoft/pylance-release#6455.
- Loading branch information
Showing
5 changed files
with
102 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# This sample is used in conjunction with final8.py to test that imported | ||
# Final symbols cannot be overwritten. | ||
|
||
from typing import Final | ||
|
||
|
||
var1: Final[int] = 1 | ||
var2: Final = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# This sample tests that final variables imported from another module | ||
# cannot be overwritten. | ||
|
||
from .final7 import * | ||
|
||
# This should generate an error. | ||
var1 = 1 | ||
|
||
# This should generate an error. | ||
var2 = 1 | ||
|
||
|
||
def func1(): | ||
from .final7 import var1, var2 | ||
|
||
# This should generate an error. | ||
var1 = 1 | ||
|
||
# This should generate an error. | ||
var2 = 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters