Skip to content

Conversation

@InvalidPathException
Copy link
Contributor

Summary

Fixes astral-sh/ty#1369

Test Plan

A new mdtest case is created
Union[Literal[1, 2, 3, 4, 5, 6, 7, 8], A, B, C, D, E, F] -> Literal[1, 2, 3, 4, 5, ... omitted 3 literals] | A | B | ... omitted 4 union elements because there was no appropriate existing case.

The non-truncation case for reveal_type has many existing tests to verify, for example, crates/ty_python_semantic/resources/mdtest/subscript/tuple.md.

Tentatively setting truncation threshold to 7. When truncated, we keep the first 5 elements.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 16, 2025

Diagnostic diff on typing conformance tests

No changes detected when running ty on typing conformance tests ✅

@github-actions
Copy link
Contributor

github-actions bot commented Oct 16, 2025

mypy_primer results

Changes were detected when running on open source projects
colour (https://github.com/colour-science/colour)
- colour/geometry/tests/test_primitives.py:782:32: error[invalid-argument-type] Argument to function `primitive_cube` is incorrect: Expected `Literal["-x", "+x", "-y", "+y", "-z", "+z", "xy", "xz", "yz", "yx", "zx", "zy"] | None`, found `list[Unknown]`
+ colour/geometry/tests/test_primitives.py:782:32: error[invalid-argument-type] Argument to function `primitive_cube` is incorrect: Expected `Literal["-x", "+x", "-y", "+y", "-z", ... omitted 7 literals] | None`, found `list[Unknown]`
- colour/geometry/tests/test_primitives.py:783:32: error[invalid-argument-type] Argument to function `primitive_cube` is incorrect: Expected `Literal["-x", "+x", "-y", "+y", "-z", "+z", "xy", "xz", "yz", "yx", "zx", "zy"] | None`, found `list[Unknown]`
+ colour/geometry/tests/test_primitives.py:783:32: error[invalid-argument-type] Argument to function `primitive_cube` is incorrect: Expected `Literal["-x", "+x", "-y", "+y", "-z", ... omitted 7 literals] | None`, found `list[Unknown]`
- colour/geometry/tests/test_vertices.py:257:41: error[invalid-argument-type] Argument to function `primitive_vertices_cube_mpl` is incorrect: Expected `Sequence[Literal["-x", "+x", "-y", "+y", "-z", "+z", "xy", "xz", "yz", "yx", "zx", "zy"]] | None`, found `list[Unknown | str]`
+ colour/geometry/tests/test_vertices.py:257:41: error[invalid-argument-type] Argument to function `primitive_vertices_cube_mpl` is incorrect: Expected `Sequence[Literal["-x", "+x", "-y", "+y", "-z", ... omitted 7 literals]] | None`, found `list[Unknown | str]`
- colour/geometry/tests/test_vertices.py:263:41: error[invalid-argument-type] Argument to function `primitive_vertices_cube_mpl` is incorrect: Expected `Sequence[Literal["-x", "+x", "-y", "+y", "-z", "+z", "xy", "xz", "yz", "yx", "zx", "zy"]] | None`, found `list[Unknown | str]`
+ colour/geometry/tests/test_vertices.py:263:41: error[invalid-argument-type] Argument to function `primitive_vertices_cube_mpl` is incorrect: Expected `Sequence[Literal["-x", "+x", "-y", "+y", "-z", ... omitted 7 literals]] | None`, found `list[Unknown | str]`
- colour/geometry/tests/test_vertices.py:269:41: error[invalid-argument-type] Argument to function `primitive_vertices_cube_mpl` is incorrect: Expected `Sequence[Literal["-x", "+x", "-y", "+y", "-z", "+z", "xy", "xz", "yz", "yx", "zx", "zy"]] | None`, found `list[Unknown | str]`
+ colour/geometry/tests/test_vertices.py:269:41: error[invalid-argument-type] Argument to function `primitive_vertices_cube_mpl` is incorrect: Expected `Sequence[Literal["-x", "+x", "-y", "+y", "-z", ... omitted 7 literals]] | None`, found `list[Unknown | str]`
- colour/geometry/tests/test_vertices.py:275:41: error[invalid-argument-type] Argument to function `primitive_vertices_cube_mpl` is incorrect: Expected `Sequence[Literal["-x", "+x", "-y", "+y", "-z", "+z", "xy", "xz", "yz", "yx", "zx", "zy"]] | None`, found `list[Unknown | str]`
+ colour/geometry/tests/test_vertices.py:275:41: error[invalid-argument-type] Argument to function `primitive_vertices_cube_mpl` is incorrect: Expected `Sequence[Literal["-x", "+x", "-y", "+y", "-z", ... omitted 7 literals]] | None`, found `list[Unknown | str]`
- colour/geometry/tests/test_vertices.py:281:41: error[invalid-argument-type] Argument to function `primitive_vertices_cube_mpl` is incorrect: Expected `Sequence[Literal["-x", "+x", "-y", "+y", "-z", "+z", "xy", "xz", "yz", "yx", "zx", "zy"]] | None`, found `list[Unknown | str]`
+ colour/geometry/tests/test_vertices.py:281:41: error[invalid-argument-type] Argument to function `primitive_vertices_cube_mpl` is incorrect: Expected `Sequence[Literal["-x", "+x", "-y", "+y", "-z", ... omitted 7 literals]] | None`, found `list[Unknown | str]`
- colour/geometry/tests/test_vertices.py:287:41: error[invalid-argument-type] Argument to function `primitive_vertices_cube_mpl` is incorrect: Expected `Sequence[Literal["-x", "+x", "-y", "+y", "-z", "+z", "xy", "xz", "yz", "yx", "zx", "zy"]] | None`, found `list[Unknown | str]`
+ colour/geometry/tests/test_vertices.py:287:41: error[invalid-argument-type] Argument to function `primitive_vertices_cube_mpl` is incorrect: Expected `Sequence[Literal["-x", "+x", "-y", "+y", "-z", ... omitted 7 literals]] | None`, found `list[Unknown | str]`

pywin32 (https://github.com/mhammond/pywin32)
- win32/test/test_win32api.py:110:42: error[invalid-argument-type] Argument to function `RegSetValueEx` is incorrect: Expected `str`, found `None | Literal["REG_SZ", "REG_EXPAND_SZ", "REG_MULTI_SZ", "REG_MULTI_SZ_empty", "REG_DWORD", "REG_QWORD_INT", "REG_QWORD", "REG_BINARY"]`
+ win32/test/test_win32api.py:110:42: error[invalid-argument-type] Argument to function `RegSetValueEx` is incorrect: Expected `str`, found `None | Literal["REG_SZ", "REG_EXPAND_SZ", "REG_MULTI_SZ", "REG_MULTI_SZ_empty", "REG_DWORD", ... omitted 3 literals]`

ibis (https://github.com/ibis-project/ibis)
- ibis/backends/impala/tests/test_exprs.py:198:60: error[invalid-argument-type] Argument to bound method `truncate` is incorrect: Expected `Literal["Y", "Q", "M", "W", "D", "h", "m", "s", "ms", "us", "ns"]`, found `Literal["y"]`
+ ibis/backends/impala/tests/test_exprs.py:198:60: error[invalid-argument-type] Argument to bound method `truncate` is incorrect: Expected `Literal["Y", "Q", "M", "W", "D", ... omitted 6 literals]`, found `Literal["y"]`
- ibis/backends/impala/tests/test_exprs.py:206:60: error[invalid-argument-type] Argument to bound method `truncate` is incorrect: Expected `Literal["Y", "Q", "M", "W", "D", "h", "m", "s", "ms", "us", "ns"]`, found `Literal["month"]`
+ ibis/backends/impala/tests/test_exprs.py:206:60: error[invalid-argument-type] Argument to bound method `truncate` is incorrect: Expected `Literal["Y", "Q", "M", "W", "D", ... omitted 6 literals]`, found `Literal["month"]`
- ibis/backends/impala/tests/test_exprs.py:210:60: error[invalid-argument-type] Argument to bound method `truncate` is incorrect: Expected `Literal["Y", "Q", "M", "W", "D", "h", "m", "s", "ms", "us", "ns"]`, found `Literal["d"]`
+ ibis/backends/impala/tests/test_exprs.py:210:60: error[invalid-argument-type] Argument to bound method `truncate` is incorrect: Expected `Literal["Y", "Q", "M", "W", "D", ... omitted 6 literals]`, found `Literal["d"]`
- ibis/backends/impala/tests/test_exprs.py:222:60: error[invalid-argument-type] Argument to bound method `truncate` is incorrect: Expected `Literal["Y", "Q", "M", "W", "D", "h", "m", "s", "ms", "us", "ns"]`, found `Literal["minute"]`
+ ibis/backends/impala/tests/test_exprs.py:222:60: error[invalid-argument-type] Argument to bound method `truncate` is incorrect: Expected `Literal["Y", "Q", "M", "W", "D", ... omitted 6 literals]`, found `Literal["minute"]`
No memory usage changes detected ✅

@InvalidPathException InvalidPathException force-pushed the invalid/truncate-wide-literals branch from 353076c to d4c6ac0 Compare October 16, 2025 19:51
@AlexWaygood AlexWaygood added ty Multi-file analysis & type inference diagnostics Related to reporting of diagnostics. labels Oct 16, 2025
@sharkdp sharkdp removed their request for review October 17, 2025 11:00
Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent, thank you!

@AlexWaygood AlexWaygood enabled auto-merge (squash) October 17, 2025 11:45
@AlexWaygood AlexWaygood merged commit fc3b341 into astral-sh:main Oct 17, 2025
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

diagnostics Related to reporting of diagnostics. ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Truncate Literal type display in some situations

2 participants