Skip to content

False-positive unsupported-operator errors for value-constrained type variable #1972

@varchasgopalaswamy

Description

@varchasgopalaswamy

Summary

I'm probably doing something wrong, but I can't figure it out. Here's a simple example of what I'm trying to do

from typing import * 

Scalar = TypeVar("Scalar", int,float)

def test(a:Scalar) -> Scalar: 
    return a * 2

reveal_type(test(10.0)) # should be float 
reveal_type(test(10)) # should be int 

Pyright works fine.

Mypy works, though I can't find a way to share a link to a playground.

pyrefly has no trouble with the operator, but thinks it's a bad return type. However, it's able to correctly infer the return types.

ty gives an unsupported operator error, and says the type of test(10.0) is float | int. Is there a more correct way to do what I'm trying to do?

Version

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinggenericsBugs or features relating to ty's generics implementation

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions