Skip to content

Bidirectional inference does not consider parameter types of constructors #1408

@sharkdp

Description

@sharkdp

Consider:

from typing import Literal

def f(default: dict[Literal["value"], str]):
    pass

# this works fine
f({"value": "hello"})

class C:
    def __init__(self, default: dict[Literal["value"], str]):
        pass

# this throws an error
C({"value": "hello"})

https://play.ty.dev/c4307737-6697-4b77-9192-1e1e6e14e70a

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

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions