Skip to content

Pyright issue with expect_request- and respond_with_json-functions #387

Closed
@JormaWuorio

Description

@JormaWuorio

This might just be something on my end, but i can not get to the bottom of this. I've gone through the documentation, gone through google, github and stackoverflow threads for something similiar but could not find nothing, also tried to implement just a simple testcase for this behaviour, but it still occurs.

I know i could get past it by using #ignore, or by not using the strict mode, but i would rather understand the problem, and where it is coming from.

Testcase straight from the docs, while using python 3.10 and pytest_httpserver 1.1.0

import requests
from pytest_httpserver import HTTPServer

def test_json_client(httpserver: HTTPServer):
    httpserver.expect_request("/foobar") # Error occurs here already
    httpserver.expect_request("/foobar").respond_with_json({"foo": "bar"}) # This line errors on both functions
    assert requests.get(httpserver.url_for("/foobar")).json() == {"foo": "bar"}

error that comes up:

Type of "expect_request" is partially unknown
  Type of "expect_request" is "(uri: str | URIPattern | Pattern[str], method: str = METHOD_ALL, data: str | bytes | None = None, data_encoding: str = "utf-8", headers: Mapping[str, str] | None = None, query_string: QueryMatcher | str | bytes | Mapping[Unknown, Unknown] | None = None, header_value_matcher: ((str, str | None, str) -> bool) | None = None, handler_type: HandlerType = HandlerType.PERMANENT, json: Any = UNDEFINED) -> RequestHandler"Pylance[reportUnknownMemberType](https://github.com/microsoft/pyright/blob/main/docs/configuration.md#reportUnknownMemberType)

and

Type of "respond_with_json" is partially unknown
  Type of "respond_with_json" is "(response_json: Unknown, status: int = 200, headers: Mapping[str, str] | None = None, content_type: str = "application/json") -> None"Pylance[reportUnknownMemberType](https://github.com/microsoft/pyright/blob/main/docs/configuration.md#reportUnknownMemberType)

I would appreciate if someone had a better understanding about this and could explain to me why this is happening, or is this something that is expected, or something to be fixed at some point?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions