Skip to content

Improve diagnostics to explain why a TypedDict is not assignable to dict #1646

@lypwig

Description

@lypwig

Question

I use a package containing methods returning poorly typed dict, and I would like to improve typing in my inherited classes by defining a typedDict and set it as a return type:

from typing import Any, TypedDict


class FooDict(TypedDict):
    a: int


class A:
    def foo(self) -> dict[str, Any]:
        return {"a": 1}


class B(A):
    def foo(self) -> FooDict: #  <-- ty error here
        return {"a": 1}

Here I get:

ty: Invalid override of method foo: Definition is incompatible with A.foo (invalid-method-override) [Ln 14, Col 9]

https://play.ty.dev/6d88c3d3-7801-46ce-98f8-8d74a0e7fce4

Is it possible to do this?

Version

ty 0.0.1-alpha.28

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions