-
Notifications
You must be signed in to change notification settings - Fork 766
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
https://github.com/microsoft/vscode/issues/229111 #6417
Comments
It's not clear to me what the issue is. Can you provide more detail on what you're seeing vs. what you are expecting. Also a simpler example with a list of package dependencies (with versions if appropriate) would help us when we try to reproduce what you're seeing.
The e: list[int] = [1]
for f in e:
pass
print(f"Before annotation: {f}")
f: list[str]
print(f"After annotation: {f}")
# Outputs:
# Before annotation: 1
# After annotation: 1 Since these two |
@jefer94, you're correct that Python allows you to assign different types to any symbol. For example: f = 1
f = "hi" However, if you use static type annotations, you are declaring that a symbol's type is limited to a particular type (or subtypes thereof). In your code, you are using such type declarations. Once you declare the type of a symbol, it is the job of a static type checker to prevent you from violating that type declaration. If you provide no type declaration for a symbol, pyright (the type checker upon which pylance is built) will allow you to assign any value to it. In your screen shot above, you have provided a type declaration for symbols For more details about type declarations, refer to this documentation. |
If that type checker applies the types statically on the scope, I think it should, or:
a = 1
a: str = "2" # TypeError: `a` is `int` and can be changed
def my_pretty_func():
a = False
def my_prettiest_func():
a = 3
a: str = "hi"
my_prettiest_func()
# more lines
print(a) Maybe the first approach is easier to apply and is better than saying that the lines 2, 4, 6, and n are |
Your mental model is a bit off here. Let me try to clear things up. If you provide a type annotation for a symbol, you are declaring its type. If you declare that the type of symbol The rules for type assignability are spelled out in the Python typing spec, which can be found here. A symbol can have only one declared type. If you attempt to declare its type multiple times in conflicting ways, a type checker will generate an error telling you about this inconsistency. Simply assigning a value to a symbol does not declare the type of that symbol. If a symbol's type hasn't been explicitly declared, it's declared type is implicitly Pylance is working as intended here, so this isn't a bug. |
The number 1 function of a highlighter is showing information that the developer can't see easily, and it's failing, even in cases easily predicable |
@jefer94, I was able to reproduce the semantic highlighting behavior that you reported in microsoft/vscode#229111. The problem there is that your first call to You may want to enable our Regarding your If you set |
I suppose that if that method isn't overloaded it will take the only return mark, so, changing class ListRecordingsRequest(TypedDict):
parent: str
page_size: int
page_token: str For class ListRecordingsRequest(TypedDict, total=False):
parent: str
page_size: int
page_token: str Fix that issue |
microsoft/vscode#229111
The text was updated successfully, but these errors were encountered: