Skip to content

Support dict literals and dict() calls as default values for parameters annotated with TypedDict types #2161

@AlexWaygood

Description

@AlexWaygood

Summary

Originally reported by @mflova in #2127 (comment). We should be able to use the type context of the parameter annotation to avoid emitting a diagnostic on either of these:

from typing import TypedDict

class Foo(TypedDict):
    x: int

def x(a: Foo = {"x": 42}): ...
def y(a: Foo = dict(x=42)): ...

Version

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bidirectional inferenceInference of types that takes into account the context of a declared type or expected typebugSomething isn't working

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions