A corner-case where type cannot be inferred #9023
Labels
addressed in next version
Issue is fixed and will appear in next published version
bug
Something isn't working
(sorry I'm not sure how to write a more informative title for this case. feel free to modify :)
Describe the bug
As in the code below, the
reveal_type
should work in theself_list += ...
line, but the actual behaviour is nothing for that line. Also, mouse hovering (in pyright playground) givesUnknown
for bothanother_self
andanother_self.list_int
; nevertheless, mouse hovering ontype(another_self)
correctly produces(variable) another_self: Self@Foo
.I have tried my best to minimise the code sample, and here are some points I want to note:
if flag1
sub-block, or only thecontinue
statement, the behaviour would become normal.self
toanother_self
instead of popping it from the list (inferred aslist[Self]
) would also make it work.append[...]
orextend([...])
works, only+=[...]
fails.type(another_self)
totype(self)
also makes it work (even still usinganother_self
insidereveal_type
).Code or Screenshots
Code sample in pyright playground
VS Code extension or command-line
pyright latest (1.381) as provided by the playground
A bit difference on VS Code
There might be some strange interaction with my local environment, so this can possibly be ignored, in favour of the more stable environment provided by the playground. However, it's also possible that some different bugs exist.
My local env: VS Code 1.93.1 (38c31bc7), extension: Python v2024.14.1, Pylance v2024.9.1
The code above behaves slightly differently in VS Code. The
reveal_type
still yields nothing in the+=
line, but mouse hovering can give(variable) list_int: list[int]
. With a bit more complication as below, I can still make hovering produceUnknown
.The text was updated successfully, but these errors were encountered: