Description
Recently I switch to use pyright as my lsp server. This server is very strict at type annotation, and I found some errors as following.
error: Type "list[int]" is not assignable to declared type "SequenceNotStr[int]"
"list[int]" is incompatible with protocol "SequenceNotStr[int]"
"index" is an incompatible type
Type "(value: int, start: SupportsIndex = 0, stop: SupportsIndex = sys.maxsize, /) -> int" is not assignable to type "(value: Any, /, start: int = 0, stop: int = ...) -> int"
Missing keyword parameter "start"
Missing keyword parameter "stop"
Position-only parameter mismatch; parameter "start" is not position-only
Position-only parameter mismatch; parameter "stop" is not position-only (reportAssignmentType)
1 error, 0 warnings, 0 informations
so I check the "index" signature of list.index and SequenceNotStr.index, found that:
>>> inspect.signature(list.index)
<Signature (self, value, start=0, stop=9223372036854775807, /)>
>>> inspect.signature(pd_typing.SequenceNotStr.index)
<Signature (self, value: 'Any', /, start: 'int' = 0, stop: 'int' = Ellipsis) -> 'int'>
The signature of list.index make me surprised. Why we set start and stop as the position-only argument to the list.index? I think defined them as position-and-keyword argument is a better idea, so that we can using keyword to set them. Meanwhile i think give default value to position-only argument is a little strange
Metadata
Metadata
Assignees
Projects
Status
Activity
JelleZijlstra commentedon May 15, 2025
I think the typing issue you see was fixed in hauntsaninja/useful_types#23 last year. We could give
list.index
positional-or-keyword arguments but I don't feel strongly.weipeng1999 commentedon May 15, 2025
Thanks for reply, but the SequenceNotStr is pandas._typing.SequenceNotStr, so it still not fix for me (its my wrong that not clearify which package the SequenceNotStr is provided). But I think this show that more third party typing system set the arguments as position-and-keyword, so this question may be more important than we think.
JelleZijlstra commentedon May 15, 2025
Well, then this is a bug in pandas.
weipeng1999 commentedon May 15, 2025
even this is a bug and we keep old behaviour, maybe at least we should clearly set the argument type of this two parameters in python standard document to guild third party package what is the correct signature of index?
feoh commentedon May 22, 2025
@weipeng1999 Pardon my ignorance, but could you please include a code snippet that's causing pyright to emit that error?
AA-Turner commentedon May 22, 2025
Closing, for help please use other fora.
A