You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This would fix the above issue, as in the case an empty list or othe rcollection Pyright could just infer the type as _T, while not disrupting other cases in which the types differ.
With this change in Pyright:
fromtypingimportreveal_typedeffoo(iter: Iterable[list[int]]) ->None:
result=next((itemforiteminiteriflen(item) >5), [])
reveal_type(result) # Revealed type is `list[int]`.
The text was updated successfully, but these errors were encountered:
max-muoto
changed the title
Empty List Default with next
Empty Collection with nextMay 30, 2024
max-muoto
changed the title
Empty Collection with next
Empty Collection Handling with nextMay 30, 2024
There are some issues when using
next
when providing an empty collection as a default, let's take this example:This leads to errors in Pyright, as
[]
is treated aslist[unknown]
. Pyright Playground.Here are the current
next
overloads:I would propose changing the second one to:
This would fix the above issue, as in the case an empty list or othe rcollection Pyright could just infer the type as
_T
, while not disrupting other cases in which the types differ.With this change in Pyright:
The text was updated successfully, but these errors were encountered: