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

Incorrect type inference in loops #2552

Closed
Molkree opened this issue Apr 8, 2022 · 2 comments
Closed

Incorrect type inference in loops #2552

Molkree opened this issue Apr 8, 2022 · 2 comments
Labels
bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version

Comments

@Molkree
Copy link

Molkree commented Apr 8, 2022

Environment data

  • Language Server version: v2022.3.4 - v2022.4.0
  • OS and version: Win10
  • Python version (& distribution if applicable, e.g. Anaconda): Python 3.10

Expected behaviour

No error.

Actual behaviour

Type of "high" is partially unknown
  Type of "high" is "int | Unknown"

Code Snippet / Additional information

def find_min(nums: list[int]) -> int:
    low = 0
    high = len(nums) - 1
    while low < high:
        mid = (low + high) // 2
        if nums[mid] > nums[high]:
            low = mid + 1
        elif nums[mid] < nums[high]:
            high = mid
        else:
            high -= 1  # <- error here
    return nums[low]

This might have the same root issue as the #2549 as it is also in a loop but this issue is present since v2020.3.4 and another one only since v2020.4.0 so I have opted to open a new ticket.

@erictraut
Copy link
Contributor

Thanks for the bug report. This will be addressed in the next release. I've added a new unit test based on your code sample to help prevent future regression.

@erictraut erictraut added bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version and removed triage labels Apr 10, 2022
@heejaechang
Copy link
Contributor

This issue has been fixed in version 2022.4.1, which we've just released. You can find the changelog here: CHANGELOG.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version
Projects
None yet
Development

No branches or pull requests

3 participants