Skip to content

Binary operators incorrectly shown as 'unsupported-operator' if defined via a factory with Callable return type #1209

@wurli

Description

@wurli

Summary

I ran into this issue when working with pyspark's Col type (from pyspark.sql.functions import col).

Here's a minimal reprex:

from typing import Callable

# Note: removing the return annotation 'fixes' the issue :)
def make_less_than() -> Callable[["MyClass", "MyClass"], bool]:
    def _(x: "MyClass", y: "MyClass") -> bool:
        return x.val < y.val
    return _

class MyClass:
    def __init__(self, val: int):
        self.val = val

    __lt__ = make_less_than()

MyClass(1) < MyClass(2) # Operator `<` is not supported for types `MyClass` and `MyClass` [unsupported-operator]

Playground link: https://play.ty.dev/d17232fa-2da8-4c04-baa7-45036bf59418

Many thanks! I've been playing around with ty on a pretty bit project and this is really the only issue I've found. Overall a fantastic experience for a project which is still in alpha ⭐

Version

ty 0.0.1-alpha.21 (ef52a19 2025-09-19)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions