Skip to content

question to the signature of list.index #134025

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

Closed
weipeng1999 opened this issue May 15, 2025 · 6 comments
Closed

question to the signature of list.index #134025

weipeng1999 opened this issue May 15, 2025 · 6 comments
Labels
docs Documentation in the Doc dir

Comments

@weipeng1999
Copy link

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

@JelleZijlstra
Copy link
Member

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
Copy link
Author

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.

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
Copy link
Member

Well, then this is a bug in pandas.

@weipeng1999
Copy link
Author

Well, then this is a bug in pandas.

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?

@picnixz picnixz added the docs Documentation in the Doc dir label May 15, 2025
@feoh
Copy link
Contributor

feoh commented 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
Copy link
Member

Closing, for help please use other fora.

A

@AA-Turner AA-Turner closed this as not planned Won't fix, can't repro, duplicate, stale May 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir
Projects
Status: Todo
Development

No branches or pull requests

5 participants