DetachHead / basedpyright

pyright fork with various type checking improvements, improved vscode support and pylance features built into the language server
https://docs.basedpyright.com
Other
1.02k stars 19 forks source link

non-literal iterators should be able to indicate that they will run at least once #407

Closed KotlinIsland closed 3 months ago

KotlinIsland commented 3 months ago

Problem:

for _ in range(1):
    a = 1
print(a)  # error: possibly undefined

Solution:

x: int
y: int
for _ in range(x, y) or (1,):
    a = 1
print(a)  # ah yes, it's defined

a once helper would be useful: it would assert that it runs at least once

x: int
y: int
for _ in once(range(x, y)):
    a = 1
print(a)  # ah yes, it's defined

Although, this could be addressed at a fundamental level.

DetachHead commented 3 months ago

Duplicate of #348

DetachHead commented 3 months ago

actually no its not, thats related to literals which is probably easier to do than this

DetachHead commented 3 months ago

actually i changed my mind i think these should both be addressed as part of the same issue