-
Notifications
You must be signed in to change notification settings - Fork 226
Closed as duplicate of#1576
Closed as duplicate of#1576
Copy link
Labels
bidirectional inferenceInference of types that takes into account the context of a declared type or expected typeInference of types that takes into account the context of a declared type or expected type
Milestone
Description
Summary
Errors not raised by mypy nor pyright
It seems that for this specific case, doing [tags] infers list[str] instead of list[Tags], which makes the assignment invalid.
from collections.abc import Sequence
from typing import Literal, TypeAlias
Tags: TypeAlias = Literal["a", "b"]
def func(tags: Tags | Sequence[Tags]) -> None:
tags = [tags] if isinstance(tags, str) else tags # error[invalid-assignment]: Object of type `list[Unknown | str] | (Sequence[Literal["a", "b"]] & ~str)` is not assignable to `Literal["a", "b"] | Sequence[Literal["a", "b"]]`Version
ty 0.0.1-alpha.28 (8c34249 2025-11-25)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bidirectional inferenceInference of types that takes into account the context of a declared type or expected typeInference of types that takes into account the context of a declared type or expected type