Search code examples
pythonfastapifile-watcherpyright

Typing.py errors when applying pyright


Good day, sirs. The following error occurs when applying pyright.

/opt/homebrew/bin/pyright /Users/pli/Desktop/develop/app/application/router/test.py
/Users/pli/Desktop/develop/app/application/router/test.py
  /Users/pli/Desktop/develop/app/application/router/test.py:21:11 - error: "int" is not defined (reportUndefinedVariable)
  /Users/pli/Desktop/develop/app/application/router/test.py:22:16 - error: "int" is not defined (reportUndefinedVariable)
  /Users/pli/Desktop/develop/app/application/router/test.py:23:15 - error: "str" is not defined (reportUndefinedVariable)
  /Users/pli/Desktop/develop/app/application/router/test.py:24:13 - error: "str" is not defined (reportUndefinedVariable)
  /Users/pli/Desktop/develop/app/application/router/test.py:33:39 - error: "int" is not defined (reportUndefinedVariable)

/opt/homebrew/cellar/python@3.11/3.11.4_1/frameworks/python.framework/versions/3.11/lib/python3.11/typing.py
  /opt/homebrew/cellar/python@3.11/3.11.4_1/frameworks/python.framework/versions/3.11/lib/python3.11/typing.py:363:54 - error: "frozenset" is not defined (reportUndefinedVariable)
  /opt/homebrew/cellar/python@3.11/3.11.4_1/frameworks/python.framework/versions/3.11/lib/python3.11/typing.py:2850:15 - error: "frozenset" is not defined (reportUndefinedVariable)
  /opt/homebrew/cellar/python@3.11/3.11.4_1/frameworks/python.framework/versions/3.11/lib/python3.11/typing.py:2854:12 - error: "frozenset" is not defined (reportUndefinedVariable)/opt/homebrew/cellar/python@3.11/3.11.4_1/frameworks/python.framework/versions/3.11/lib/python3.11/typing.py:2920:15 - error: "type" is not defined (reportUndefinedVariable)
  /opt/homebrew/cellar/python@3.11/3.11.4_1/frameworks/python.framework/versions/3.11/lib/python3.11/typing.py:3068:14 - error: "type" is not defined (reportUndefinedVariable)
  /opt/homebrew/cellar/python@3.11/3.11.4_1/frameworks/python.framework/versions/3.11/lib/python3.11/typing.py:2929:22 - error: "type" is not defined (reportUndefinedVariable)
  /opt/homebrew/cellar/python@3.11/3.11.4_1/frameworks/python.framework/versions/3.11/lib/python3.11/typing.py:488:16 - error: "type" is not defined (reportUndefinedVariable)
  /opt/homebrew/cellar/python@3.11/3.11.4_1/frameworks/python.framework/versions/3.11/lib/python3.11/typing.py:2728:15 - error: "dict" is not defined (reportUndefinedVariable)
  /opt/homebrew/cellar/python@3.11/3.11.4_1/frameworks/python.framework/versions/3.11/lib/python3.11/typing.py:1558:16 - error: "isinstance" is not defined (reportUndefinedVariable)
  /opt/homebrew/cellar/python@3.11/3.11.4_1/frameworks/python.framework/versions/3.11/lib/python3.11/typing.py:1561:18 - error: "tuple" is not defined (reportUndefinedVariable)

  1. reinstalled pyright via homebrew and applied it.
  2. reset the file watchers in the pycharm settings.

I was not getting any errors before, but suddenly started getting them.

+ test.py

from fastapi import APIRouter, Header, Query
...

router = APIRouter(tags=["Test"])

@router.get("/api/v1/test/{id_}")
async def get_test_(id_: str) -> TestResponse | None:
    return await get_test(id_=id_)


@router.post("/api/v1/test/")
async def add_email_paste_parsing_info_(
    data: TestRequest, operator_id: int = Header(include_in_schema=False)
) -> TestResponse:
    return await add_email_paste_parsing_info(data, operator_id)

Solution

  • I suppose you have solved it already. This behaviour of pyright was only around version 1.1.357 ... I tested that version 1.1.355 and later 1.1.359 don't behave like that.