-
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
I'm guessing that you have "strict" type checking mode enabled? The 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 |
Beta Was this translation helpful? Give feedback.
-
passing a typeguard might work import pytest
from responses import Call
import responses
from typing import List, Sequence, TypeGuard
def is_call_typeguard(call: Call) -> TypeGuard[Call]:
"""Check if the call is to the target URL."""
if call.request.url is not None:
return call.request.url.startswith("https://foo.example.com")
return False
@pytest.fixture
def req_mock():
with responses.RequestsMock() as mock:
yield mock
@pytest.fixture
def foo_request(req_mock: responses.RequestsMock):
req_mock.add(responses.GET, url="https://foo.example.com/123")
yield filter(is_call_typeguard, req_mock.calls) |
Beta Was this translation helpful? Give feedback.
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.
The problem stems from the fact that
req_mock.calls
is of typeCallList
, which derives fromSequence[Any]
. That means a static type checker knows thatCallList
is iterable, but it doesn't know what type it is iterating over. And that, in turn, means that a call tofilter
…