Skip to content

False negative assigning incompatible generic function to generic callback protocol #5736

Open

Description

@randolf-scholz

Describe the Bug

both IntMap and int_mapping are not assignable to SelfMap (because they do not accept str argument, for instance), but pyrefly only rejects the protocol.

from typing import Protocol

class SelfMap(Protocol):
    def __call__[T](self, arg: T) -> T: ...

class IntMap(Protocol):
    def __call__[T: int](self, arg: T) -> T: ...

def int_mapping[T: int](self, arg: T) -> T: ...

def check_proto(arg: IntMap) -> SelfMap:
    return arg  # ERROR (true positive ✅️)

def check_impl() -> SelfMap:
    return int_mapping  # NO ERROR (false negative ❌️)

Sandbox Link

https://pyrefly.org/sandbox/?project=v2.lVVBTsMwEPzKilxyik9ccufApUVROAGKTHDTiDaOYgcVIY7ckPgA_IP38AG-wHgdNw2qCj0m3h2vd2dmj7DMYGmjkpy1wTTicBLY4zVVomFFcZXf7EohZ0rkKSVJMgKdN_ZvnBTztgfBXDxiwBw2sv-mlEtV3hetuzzmIF8ORw5PDGTYipUoorMsm2cUW3CMWm1qHuXX-8v35xvzdMRGB1deDHvxdmp2uLN5gF5IKI4aVUmP_fHqsTHf3tYr42cV0SU-avu4tQ62S_YS3a0l1ki_vlVdvOF-cB3Q-rSGxfXJjKNSeto8DxT7RfCILvwPGrgCa4cyqh4LBLeioREeqGhpbWtSIUK67iqhGnGnSyMmGcIVSPJB1ryWpnCkWZAGsPuVdcpVHmL3Dw

(Only applicable for extension issues) IDE Information

No response

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions