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 reportPrivateImportUsage error with typical imports #4548

Closed
gitpushdashf opened this issue Apr 21, 2022 · 2 comments
Closed

pyright reportPrivateImportUsage error with typical imports #4548

gitpushdashf opened this issue Apr 21, 2022 · 2 comments

Comments

@gitpushdashf
Copy link

I have a very simple script here:

from time import time, sleep
from typing import Iterator

from flask import Flask, Response


def main() -> None:
    app = Flask("Testing server")

    last_started = int(time())
    @app.route("/reload", methods=["GET"])
    def reload() -> Response:
        def stream() -> Iterator[str]:
            # When this is reloaded, it will actually break the connection.
            while True:
                yield f"data: {last_started}\n\n"
                sleep(1)  # pragma: nocover

        return Response(stream(), mimetype="text/event-stream")

    app.run(host="127.0.0.1", port=3001, use_reloader=True)


if __name__ == "__main__":
    main()

mypy --strict is happy with it.

However, pyright is not.

$ pyright server.py
Searching for source files
Found 1 source file
server.py
  server.py:4:26 - error: "Response" is not exported from module "flask.app"
    Import from "flask.wrappers" instead (reportPrivateImportUsage)
1 error, 0 warnings, 0 informations
Completed in 1.155sec

I was surprised, at first, thinking this was a pyright bug. But perhaps it's not?

microsoft/pyright#2639

@davidism
Copy link
Member

Update to the latest version of Flask. If that doesn't fix it, it's a bug with pyright.

@gitpushdashf
Copy link
Author

I'm using flask 2.1.1, which is currently the latest version.

You can see the pyright explanation here: https://github.com/microsoft/pyright/blob/main/docs/typed-libraries.md#library-interface

I wonder if it follows PEP-561 more strictly than mypy.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants