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:
- Reproduces with Basilisk 0.38.0 and 0.37.3.
-
- Reproduces with default bundled/unpinned Typeshed; no pin is required.
-
-
-
-
- Environment: Windows 11 x86_64, Python 3.12.12, Basilisk 0.38.0.
Full verified reproduction details:
Minimal reproduction
Basilisk 0.38.0 reports:
Expected
No diagnostic.
UserIdis 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:
The equivalent legacy declaration also passes:
This narrows the problem to direct return-expression analysis of a PEP 695 alias used as the target of
cast().Additional details: