Skip to content

Inconsistent callable inference between direct method assignment and wrapper-returned method #2293

@Cjkjvfnby

Description

@Cjkjvfnby

Summary

This code sample works with Mypy and fails on ty.

No additional configurations, only run: ty check

from typing import Callable


def _method(self: "Foo") -> "Foo":
    return Foo()


def _method_wrapper(
) -> Callable[["Foo"], "Foo"]:
    return _method


class Foo:    
    direct_assignment =  _method
    assign_via_wrapper = _method_wrapper()


def boo(c: Foo) -> None:
    c.direct_assignment()
    c.assign_via_wrapper()
# | ^^^^^^^^^^^^^^^^^^^^^^
# |
# info: Union variant `(Foo, /) -> Foo` is incompatible with this call site
# info: Attempted to call union type `Unknown | ((Foo, /) -> Foo)`
# info: rule `missing-argument` is enabled by default

The original problem was discovered when using PySpark 3.4 https://github.com/apache/spark/blob/branch-3.4/python/pyspark/sql/column.py#L1065

from pyspark.sql.column import Column
def foo(c: Column) -> Column:
    return c.desc()

Version

0.0.8

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions