Skip to content

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

@Jammf

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)

Metadata

Metadata

Assignees

Labels

bidirectional inferenceInference of types that takes into account the context of a declared type or expected type

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions