Skip to content

prefer more precise declared type over gradual inferred type #136

@carljm

Description

@carljm

In a case like this:

from typing import Any

def f(x: Any):
    y: str = x
    reveal_type(y)

We currently reveal Any because we prefer inferred over declared type. But in this case that's counter productive because our inferred type is just Any.

One policy we could use here is that if the declared type is assignable to the inferred type, that suggests it is at least as precise, and we should prefer it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions