Skip to content

PEP 695 alias reported undefined in direct return from cast #372

Description

@rayliverified

Full verified reproduction details:

Minimal reproduction

from typing import cast

type UserId = int


def parse(value: object) -> UserId:
    return cast(UserId, value)

Basilisk 0.38.0 reports:

error[names_undefined]: Function `parse` returns `UserId` but `UserId` is not defined in this scope
  --> repro.py:7:17
7 |     return cast(UserId, value)
  |                 ^^^^^^

Expected

No diagnostic. UserId is a valid PEP 695 type alias. Python 3.12.12, ty 0.0.29, and mypy 2.3.0 all accept this file.

Passing controls

Assigning the cast to a typed local before returning passes Basilisk:

def parse(value: object) -> UserId:
    result: UserId = cast(UserId, value)
    return result

The equivalent legacy declaration also passes:

from typing import TypeAlias
UserId: TypeAlias = int

This narrows the problem to direct return-expression analysis of a PEP 695 alias used as the target of cast().

Additional details:

Metadata

Metadata

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