Skip to content

Avoid literal promotion when constructing frozenset from list/set literal #2280

Description

@Jammf

Summary

Literal promotion is currently performed for tuple but not for frozenset. This is surprising to me given that they both are immutable and behave somewhat similarly. It could be useful to change frozenset, for instance to support the following comparisons:

from typing import reveal_type

# tuple
reveal_type((1, 2))  # Revealed type: `tuple[Literal[1], Literal[2]]`
reveal_type((1, 2) == (1, 2))  # Revealed type: `Literal[True]`

# frozenset
reveal_type(frozenset({1, 2}))  # Revealed type: `frozenset[Unknown | int]`
reveal_type(frozenset({1, 2}) == frozenset({1, 2}))  # Revealed type: `bool`
reveal_type(frozenset({1, 2}) == frozenset({2, 1}))  # Revealed type: `bool`

https://play.ty.dev/464c2ef8-e7bc-4e74-938f-3c0f2cd20916

Related: #1284 (comment)

Version

ty 0.0.8 (aa7559d 2025-12-29)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bidirectional inferenceInference of types that takes into account the context of a declared type or expected typegenericsBugs or features relating to ty's generics implementationliteral-typesLiteral and LiteralString type inference, promotion, narrowing, assignability, and display

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions