Skip to content

Can it be a bug in the latest version of Pyright? #8164

Answered by erictraut
rafrafek asked this question in Q&A
Discussion options

You must be logged in to vote

I'm guessing that you have "strict" type checking mode enabled? The reportUnknownParameterType check is disabled by default in pyright.

Pyright 1.1.347 is quite old. The behavior with more recent versions looks correct to me. Let's simplify the code to see what's going on.

def test(req_mock: responses.RequestsMock):
    x = filter(lambda r: r.request.url.startswith(""), req_mock.calls)
    reveal_type(x) # filter[Unknown]

The problem stems from the fact that req_mock.calls is of type CallList, which derives from Sequence[Any]. That means a static type checker knows that CallList is iterable, but it doesn't know what type it is iterating over. And that, in turn, means that a call to filter

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@rafrafek
Comment options

Answer selected by rafrafek
Comment options

You must be logged in to vote
1 reply
@rafrafek
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants