pallets/flask

Pyright type errors: `src/flask/app.py`

brendon-codes opened this issue · 3 comments

Pyright reports type errors for src/flask/app.py:

flask/src/flask/app.py
  flask/src/flask/app.py:352:20 - error: Expression of type "BufferedReader" is incompatible with return type "IO[AnyStr@open_resource]"
    "BufferedReader" is incompatible with "IO[AnyStr@open_resource]"
      Type parameter "AnyStr@IO" is invariant, but "bytes" is not the same as "AnyStr@open_resource" (reportReturnType)
  flask/src/flask/app.py:1178:21 - error: Expression with type "Tuple[ResponseValue, HeadersValue] | Tuple[ResponseValue, int] | Tuple[ResponseValue, int, HeadersValue]" cannot be assigned to target tuple
    Type "Tuple[ResponseValue, int, HeadersValue]" is incompatible with target tuple
      Tuple size mismatch; expected 2 but received 3 (reportAssignmentType)
  flask/src/flask/app.py:1205:28 - error: Argument of type "HeadersValue | int | None" cannot be assigned to parameter "status" of type "int | str | HTTPStatus | None" in function "__init__" (reportArgumentType)
  flask/src/flask/app.py:1240:29 - error: Cannot assign to attribute "status" for class "Response" (reportAttributeAccessIssue)
  flask/src/flask/app.py:1242:34 - error: Cannot assign to attribute "status_code" for class "Response"
    Type "HeadersValue | int" is incompatible with type "int"
      "Mapping[str, HeaderValue]" is incompatible with "int" (reportAttributeAccessIssue)

Command which was run:

source .venv/bin/activate
pyright

Environment:

  • Python version: 3.12
  • Flask version: 3.1.0

Thanks for checking this and submitting a fix!

No need to report separate issues for each file. You can report and fix errors all in one go.

Why did you run the command like that as opposed to running the plain pyright command in the project? It should automatically use the venv and pyproject config.

Hi @davidism :

Thanks for checking this and submitting a fix!

Yes and thank you for everything you do on Flask. It's been on my todo for a long time to help out more with the project.

No need to report separate issues for each file. You can report and fix errors all in one go.

Would you prefer that I combine those PRs?

Why did you run the command like that as opposed to running the plain pyright command in the project? It should automatically use the venv and pyproject config.

Good point. I was running it without activating the virtualenv. I will update the description to make it more idiomatic.

Yes, please report a single issue and make a single PR. "Fix pyright findings" is fine. You can split it into multiple commits if you think it makes fixing/reviewing easier.