Skip to content
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

"Partially unknown" message in for loop. #9496

Closed
sindzicat opened this issue Nov 22, 2024 · 6 comments
Closed

"Partially unknown" message in for loop. #9496

sindzicat opened this issue Nov 22, 2024 · 6 comments
Assignees
Labels
as designed Not a bug, working as intended bug Something isn't working

Comments

@sindzicat
Copy link

Hello!

When I type:

arr1: list[int] = [1, 2, 3, 4, 5]
arr2: list[float] = [5/2, 3/2, 7/2]
el: int | float

for el in [*arr1, *arr2]:
    print(el)

I get an error message for el variable:

Type of "el" is partially unknown
  Type of "el" is "Unknown | int | float"Pylance[reportUnknownVariableType](https://github.com/microsoft/pyright/blob/main/docs/configuration.md#reportUnknownVariableType)
(variable) el: Unknown | int | float

Image

Then I changed my code slightly, replaced [*arr1, *arr2] with arr1 + arr2. The error message gone. Modified code, that works:

arr1: list[int] = [1, 2, 3, 4, 5]
arr2: list[float] = [5/2, 3/2, 7/2]
el: int | float

for el in arr1 + arr2:
    print(el)
Version: 1.95.3 (user setup)
Commit: f1a4fb101478ce6ec82fe9627c43efbf9e98c813
Date: 2024-11-13T14:50:04.152Z
Electron: 32.2.1
ElectronBuildId: 10427718
Chromium: 128.0.6613.186
Node.js: 20.18.0
V8: 12.8.374.38-electron.0
OS: Windows_NT x64 10.0.17763
Name: Pylance
Id: ms-python.vscode-pylance
Description: A performant, feature-rich language server for Python in VS Code
Version: 2024.11.101
Publisher: Microsoft
VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=ms-python.vscode-pylance

It seems to me, I found a bug.

@erictraut
Copy link
Collaborator

Could someone from the pylance team please transfer this to the pyright project? Thanks!

@sindzicat, I presume that you're using "strict" type checking mode? The reportUnknownVariableType check is not enabled by default in "standard" or "basic" type checking modes, so I wouldn't expect this error to show up when using default settings. Are there any other non-default settings that you're using?

Based on your description, this sounds like a bug, but I'm unable to repro it with the code sample you've provided. Could you confirm that you're able to repro the problem with a new project and a new source file with only the contents of the code above?

Are members of the pylance team able to repro this?

@sindzicat
Copy link
Author

sindzicat commented Nov 22, 2024

@erictraut, yes, I use "strict" type checking mode.

All settings I modified for Pylance:

Image

Originally I wanted to create this issue in pyright repo first, but then decided it's for Pylance. I may to recreate my issue in pyright repo if needed. Moved already.

@rchiodo rchiodo transferred this issue from microsoft/pylance-release Nov 22, 2024
@erictraut
Copy link
Collaborator

I'm not able to repro the problem. Here it is in pyright playground.

Could you confirm that you're able to repro the problem with a new project and a new source file with only the contents of the code above?

@erictraut erictraut added bug Something isn't working question Further information is requested labels Nov 22, 2024
@sindzicat
Copy link
Author

sindzicat commented Nov 23, 2024

@erictraut, I used pre-release version of Pylance. I switched back to production version of Pylance, but I still see this error.

I see that pyright works correctly in playground.

How can I check, what pyright version is used in Pylance? Thanks!

@Azureblade3808
Copy link
Contributor

Azureblade3808 commented Nov 26, 2024

The key may be strictListInference=false.

Image

There is an option for it in Pylance, which is disabled by default.

Image

@erictraut
Copy link
Collaborator

If you enable strict mode but disable strictListInference, you will see this error. This is expected, so it's not a bug. Refer to the pyright documentation for more details.

@erictraut erictraut closed this as not planned Won't fix, can't repro, duplicate, stale Nov 29, 2024
@erictraut erictraut added as designed Not a bug, working as intended and removed question Further information is requested labels Nov 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
as designed Not a bug, working as intended bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants