Skip to content

Importing a type alias introduces Unknown as a possible type #433

@lucach

Description

@lucach

Summary

On the following code, ty correctly reports that the argument to function f is incorrect (playground):

class A: pass
B = A
def f(b: B): pass
f("")  # Argument to function `f` is incorrect: Expected `A`, found `Literal[""]` (invalid-argument-type) [Ln 4, Col 3]

When the last two lines are moved into a separate file, and B is imported, ty no longer detects the error (playground):

from main import B
def f(b: B): pass
f("")

In the main file, the implicit type alias B is correctly inferred to be <class 'A'>. But when it's imported from another module, ty infers Unknown | <class 'A'>.

I'm not sure how broad the actual underlying issue is.

Version

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionAsking for support or clarification

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions