Skip to content

Function invocation pins type of arguments too early #105

Closed
1 of 1 issue completed
Closed

Description

@grievejia

Minimal repro:

def foo[T](a: T, b: T) -> T:
    ...

def test(x: int | None, y: int | None) -> int | None:
    if x is None:
        return foo(x, y)
    return None

Expected: No error
Actual: Argument int | None is not assignable to parameter b with type None in function foo [bad-argument-type]

Activity

  1. added theissue type on Apr 16, 2025
  2. added this to the V1 Release milestone on May 15, 2025
  3. martindemello commented on Jun 29, 2025

    @martindemello

    i don't understand the initial example - if x is None coerces the type of x to None and then foo(x, y) could indeed fail typechecking if y is int, so pyrefly is doing the right thing there.

  4. grievejia commented on Jul 7, 2025

    @grievejia
    ContributorAuthor

    @martindemello If the typevar T for foo gets instantiated into int | None then type checking won't fail. i.e.

    def foo(a: int | None, b: int | None) -> int | None:
        ...
    
    def test(x: int | None, y: int | None) -> int | None:
        if x is None:
            return foo(x, y)  # This should type check
        return None

    We don't really want to assume the call foo(x, y) forces T to be None just because its first argument x is None -- the point here is that if we wait longer and get to see what the type of y is, we could have guessed better type for T.

  5. samwgoldman commented on Jul 7, 2025

    @samwgoldman
    Member

    If I understand, the following is a even simpler example where the eager pinning of generics can go awry:

    def foo[T](a: T, b: T) -> T: ...
    foo(0, 1.)   # Argument `float` is not assignable to parameter `b` with type `int` in function `foo`
    
  6. self-assigned this
    on Jul 15, 2025
  7. github-actions commented on Aug 5, 2025

    @github-actions

    This issue has someone assigned, but has not had recent activity for more than 2 weeks.

    If you are still working on this issue, please add a comment so everyone knows. Otherwise, please unassign yourself and allow someone else to take over.

    Thank you for your contributions!

  8. 226 remaining items

  9. rchen152 commented on Apr 30, 2026

    @rchen152
    Contributor

    Most of the user-facing bugs that were reported on this issue and its duplicates have been closed, so I'm going to close out this issue and open a new one to track the remaining work (edge case bugs, internal solver improvements and cleanups).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

googleissues from googlepytorchtypecheckingusabilityUsability & readiness issues identified with running Pyrefly on top OSS projects

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions