Skip to content

abs(float) reveals Unknown for function parameters but int | float at module scope #3333

@SigureMo

Description

@SigureMo

Summary

ty appears to infer inconsistent types for abs(size) depending on whether the same float annotation appears on a function parameter or a module-level variable.

Playground: https://play.ty.dev/1f3fa1f1-b2ca-4d4d-8cde-05e7adfc1291

Minimal reproduction:

from typing import reveal_type

def fn(size: float):
    size_ = abs(size)
    reveal_type(size_)  # ty: Unknown

size: float = 1.0
size_ = abs(size)
reveal_type(size_)  # ty: int | float

Command:

ty check repro.py

Actual output with ty 0.0.32:

reveal_type(size_)  # inside function: Unknown
reveal_type(size_)  # module scope: int | float

Version

ty 0.0.32 (4d1e1fc 2026-04-20)

Metadata

Metadata

Assignees

No one assigned

    Labels

    genericsBugs or features relating to ty's generics implementation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions