skip to Main Content

How to avoid this VSCode + Pylance static type check error?

def process_row(row: dict[str, Any]):
    row = SimpleNamespace(**row)

For this, vscode shows red underline for SimpleNamespace(**row) with messsage: Expression of type "SimpleNamespace" cannot be assigned to declared type "dict[str, Any]"

2

Answers


  1. Chosen as BEST ANSWER

    After more searching and going through github issues for pylance and mypy, it appears that this is legitimate open issue for pylance.

    mypy kind of fixed this. For above function, running mypy typetest.py gave 1 error: Name "row" already defined on line 5 but rnunning with mypy --allow-redefinition typetest.py was all green.

    You can not yet turn of this in pylance it seems but let people know here if anyone point this out. Thanks.


  2. You can add the following codes to your settings.json in .vscode folder to turn off error warning:

    "python.analysis.diagnosticSeverityOverrides": {
        "reportGeneralTypeIssues": "none"
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search