Skip to content

map subscript load over unions and intersections #625

@carljm

Description

@carljm

An example I got from reviewing astral-sh/ruff#17643, which may or may not be related to this issue. I find it strange that we infer Unknown here, and not some @Todo type?

from typing import reveal_type


def _(union_of_tuples: tuple[int] | tuple[None]):
    reveal_type(union_of_tuples[0])  # Unknown

Originally posted by @sharkdp in #493

It looks to me like the issue here is that TypeInferenceBuilder::infer_subscript_expression_types has no case for handling unions or intersections, by mapping the subscript operation over the element types and unioning/intersecting the results.

Metadata

Metadata

Labels

help wantedContributions especially welcometyping semanticstyping-module features, spec compliance, etc

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions