Skip to content

generic inference fails in some cases with function argument type like Foo[T, object] | Foo[object, T] #3583

Description

@DetachHead

Describe the Bug

class Foo[T, U]:
    def t(self) -> T: ...
    def u(self) -> U: ...


def fn[T](foo: Foo[T, object] | Foo[object, T], value: list[T]) -> T: ...


def fn2[T](value: list[T]) -> T:
    return fn(Foo[T, object](), value)
ERROR sandbox.py:10:12-39: Returned type `object` is not assignable to declared return type `T` [bad-return]
ERROR sandbox.py:10:33-38: Argument `set[T]` is not assignable to parameter `value` with type `set[object]` in function `fn` [bad-argument-type]

Python: 3.13

Sandbox Link

https://pyrefly.org/sandbox/?project=N4IgZglgNgpgziAXKOBDAdgEwEYHsAeAdAA4CeSIAxlKnHAAQBiuuA2gCoA09AqgLqIAOunqj6mGGHoAXABRwYUMAEp6AWgB89donqF9wseMn0ArvMUr1Wnrv2FhjrCbDoOfWWBa7mbLvVxsACsYSmk%2BegAfJhZWQJCw7nY%2BbgA3VChTGF0oCDhpd1VNbTsDdCcJKVcAJndZdMzs%2Blz8wusSwzEAJxhpUy6RV1lfDm540PDZZTSMrOUQThAyHrAoUkJpXABbKAoyaQALXHQ1VJguuAhj%2BgBeekEQAGZCAEZqh%2BFWc67cC75hDDoXDSVDSK4nLZ5LagygHW70ADk31%2BCOEIAAvotUGEIGdGNAYBQ0Fg8EQyBigA

(Only applicable for extension issues) IDE Information

No response

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions