No type hint with return values for TypedDict in PyCharm


Atm I am starting with the typing library. When I create a wrong dict in-line I will get a typehint that the created dictionary is indeed not correct, and ‘type hint’: 42 is highlighted.

Is it normal that the wrong return value in the function is not highlighted? Which is ‘no type hint’: 88 in this case.

from typing import TypedDict

class Test(TypedDict):
    asdf: str
    a1: int

asdf: Test = {'type hint': 42}

def raw_to_prop() -> Test:
    return {'no type hint': 88}

Asked By: Bart



I think this question should end up getting closed, but here’s what I see in PyCharm 2022.2.3 with a Python 3.10 environment on Windows 10:

enter image description here


enter image description here

Note that the squigly lines are the result of there not being sufficient empty lines between the function definitions and the rest of the main body code.

Answered By: Grismar
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.