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

reportUnusedVariable false positives when used with an Unknown list #3545

Closed
Avasam opened this issue Jun 6, 2022 · 3 comments
Closed

reportUnusedVariable false positives when used with an Unknown list #3545

Avasam opened this issue Jun 6, 2022 · 3 comments
Labels
addressed in next version Issue is fixed and will appear in next published version bug Something isn't working

Comments

@Avasam
Copy link

Avasam commented Jun 6, 2022

Note: if you are reporting a wrong signature of a function or a class in the standard library, then the typeshed tracker is better suited for this report: https://github.com/python/typeshed/issues.

Describe the bug
In the example below, read is unknown. So image is unknown as well. Pyright doesn't see that I do use the variable x to slice or access the image. Note this doesn't happen at the top level, it has to be inside of a function.

To Reproduce
See minimal repro below

Expected behavior
No errors

Screenshots or Code
If applicable, add screenshots or the text of the code (surrounded by triple back ticks) to help explain your problem.

import cv2


def __example(capture_device: cv2.VideoCapture):
    _, image = capture_device.read()
    x = 1
    image[x]

image

C:\Users\Avasam\Documents\Git\Auto-Split\src\region_capture.py
C:\Users\Avasam\Documents\Git\Auto-Split\src\region_capture.py:139:5 - error: Variable "y" is not accessed (reportUnusedVariable)
C:\Users\Avasam\Documents\Git\Auto-Split\src\region_capture.py:140:5 - error: Variable "x" is not accessed (reportUnusedVariable)

I don't think it's specific to cv2, but I'm using the types bundled with microsoft/python-type-stubs

VS Code extension or command-line
[email protected]

@erictraut erictraut added the bug Something isn't working label Jun 6, 2022
@erictraut
Copy link
Collaborator

Thanks for the bug report. This will be addressed in the next release. It stems from a bug in the type stubs where VideoCapture is declared in a circular fashion.

VideoCapture = _mod_cv2.VideoCapture

Since _mod_cv2 refers back to the same type stub, this is effectively the same as

VideoCapture = VideoCapture

Pyright detects this case and reports an error, but it didn't properly handle the resulting type, and this propagated up to eventually cause the problem you observed.

@erictraut erictraut added the addressed in next version Issue is fixed and will appear in next published version label Jun 6, 2022
@erictraut
Copy link
Collaborator

I've also filed this bug to report the circular type aliases in the stub.

@erictraut
Copy link
Collaborator

This is addressed in pyright 1.1.253, which I just published. It will also be included in the next release of pylance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addressed in next version Issue is fixed and will appear in next published version bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants