Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[ty] Infer mismatched literal comparisons#26313

Merged
charliermarsh merged 3 commits into
mainfrom
charlie/infer-mismatched-literal-comparisons
Jun 24, 2026
Merged

[ty] Infer mismatched literal comparisons#26313
charliermarsh merged 3 commits into
mainfrom
charlie/infer-mismatched-literal-comparisons

Conversation

@charliermarsh

@charliermarsh charliermarsh commented Jun 24, 2026

Copy link
Copy Markdown
Member

Summary

We already infer equality results for literal values of the same kind, but mismatched literal kinds fell through to dunder lookup and produced bool. As a result, direct comparisons such as 1 == "" remained ambiguous, as did tuple comparisons whose corresponding elements had different literal kinds.

This adds a narrow expression-inference case for mismatched built-in int, bool, str, and bytes literals. It also handles LiteralString compared with non-string literals while preserving bool for LiteralString compared with a particular string literal, since those values may be equal.

reveal_type(1 == "")  # Literal[False]
reveal_type(True != "")  # Literal[True]

left = (1, 2)
right = (1, "two")
reveal_type(left == right)  # Literal[False]

@charliermarsh charliermarsh added the ty Multi-file analysis & type inference label Jun 24, 2026
@astral-sh-bot

astral-sh-bot Bot commented Jun 24, 2026

Copy link
Copy Markdown

Typing conformance results

No changes detected ✅

Current numbers
The percentage of diagnostics emitted that were expected errors held steady at 94.37%. The percentage of expected errors that received a diagnostic held steady at 89.00%. The number of fully passing files held steady at 94/134.

@astral-sh-bot

astral-sh-bot Bot commented Jun 24, 2026

Copy link
Copy Markdown

Memory usage report

Memory usage unchanged ✅

@astral-sh-bot

astral-sh-bot Bot commented Jun 24, 2026

Copy link
Copy Markdown

ecosystem-analyzer results

Lint rule Added Removed Changed
invalid-return-type 0 1 0
Total 0 1 0

Flaky changes detected. This PR summary excludes flaky changes; see the HTML report for details.

Raw diff:

discord.py (https://github.com/Rapptz/discord.py)
- discord/audit_logs.py:210:12 error[invalid-return-type] Return type does not match returned value: expected `list[tuple[Object, PermissionOverwrite]]`, found `list[tuple[Role | Member | User | Object, PermissionOverwrite]]`

Full report with detailed diff (timing results)

@charliermarsh charliermarsh marked this pull request as ready for review June 24, 2026 01:57
@charliermarsh charliermarsh requested a review from a team as a code owner June 24, 2026 01:57
@astral-sh-bot astral-sh-bot Bot requested a review from carljm June 24, 2026 01:57

@carljm carljm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice!

Comment thread crates/ty_python_semantic/resources/mdtest/comparison/strings.md
@charliermarsh charliermarsh enabled auto-merge (squash) June 24, 2026 09:59
@charliermarsh charliermarsh merged commit 42b7cdb into main Jun 24, 2026
61 of 62 checks passed
@charliermarsh charliermarsh deleted the charlie/infer-mismatched-literal-comparisons branch June 24, 2026 10:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants