Skip to content
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

Pyright issue with expect_request- and respond_with_json-functions #387

Open
JormaWuorio opened this issue Dec 17, 2024 · 3 comments
Open

Comments

@JormaWuorio
Copy link

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?

@csernazs
Copy link
Owner

Hi @JormaWuorio ,

Thanks for the report, I had no time to look at it closely yet but for the first sight I think the issue is with the (few) Unknown types in the function parameters.

Were you able to reproduce this with a command line or do you get it from your IDE?

In case of the command line, could you share it? Just to be on the same page.

Zsolt

@JormaWuorio
Copy link
Author

I got that from vscode, did not test cli, but will try to remember tomorrow!

@csernazs
Copy link
Owner

csernazs commented Dec 17, 2024

I could reproduce it, as you said type checking mode "python.analysis.typeCheckingMode": "strict" needs to be set to strict.

It can also be reproduced in CLI. Creating a pyrightconfig.json with contents:

{                                           
  "strict": ["**/*.py"]  // Enable strict mode for all Python files
}

Then run pyright.

I'll see what can I do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants