Skip to content

[ty] Modernize setup of union types in mdtests#25291

Merged
sharkdp merged 3 commits into
mainfrom
codex/mdtest-union-parameters
May 21, 2026
Merged

[ty] Modernize setup of union types in mdtests#25291
sharkdp merged 3 commits into
mainfrom
codex/mdtest-union-parameters

Conversation

@sharkdp

@sharkdp sharkdp commented May 21, 2026

Copy link
Copy Markdown
Contributor

Remember when we wrote x = 1 if flag else None because we couldn't infer types from annotated parameters and/or couldn't understand union type annotations? This PR modernizes our mdtests to simply use annotated function parameters in those cases (I manually rejected some rewrites when the new style was less clear, for example when the generated union type itself was hard to spell).

The motivation for this is to set a better precedent for agents, as I've seen them repeating that x if flag else y pattern, which is really unnecessary, longer and harder to read in most cases.

@astral-sh-bot astral-sh-bot Bot added the ty Multi-file analysis & type inference label May 21, 2026
@sharkdp sharkdp changed the title [ty] Modernize mdtest union setup [ty] Modernize setup of union types May 21, 2026
Comment thread crates/ty_python_semantic/resources/mdtest/call/constructor.md Outdated
Comment thread crates/ty_python_semantic/resources/mdtest/call/functools_partial.md Outdated
Comment thread crates/ty_python_semantic/resources/mdtest/call/union.md Outdated
Comment thread crates/ty_python_semantic/resources/mdtest/conditional/if_statement.md Outdated
Comment thread crates/ty_python_semantic/resources/mdtest/narrow/conditionals/is_not.md Outdated
Comment thread crates/ty_python_semantic/resources/mdtest/narrow/conditionals/is_not.md Outdated
Comment thread crates/ty_python_semantic/resources/mdtest/narrow/conditionals/not.md Outdated
Comment thread crates/ty_python_semantic/resources/mdtest/narrow/boolean.md Outdated
Comment thread crates/ty_python_semantic/resources/mdtest/narrow/boolean.md Outdated
Comment thread crates/ty_python_semantic/resources/mdtest/narrow/match.md Outdated
Comment thread crates/ty_python_semantic/resources/mdtest/metaclass.md Outdated
@sharkdp sharkdp marked this pull request as ready for review May 21, 2026 12:26
@sharkdp sharkdp changed the title [ty] Modernize setup of union types [ty] Modernize setup of union types in mdtests May 21, 2026
Comment thread crates/ty_python_semantic/resources/mdtest/class/super.md Outdated
Comment thread crates/ty_python_semantic/resources/mdtest/narrow/conditionals/is.md Outdated
Comment thread crates/ty_python_semantic/resources/mdtest/narrow/conditionals/is.md Outdated
Comment thread crates/ty_python_semantic/resources/mdtest/class/super.md Outdated
@AlexWaygood AlexWaygood added the testing Related to testing Ruff itself label May 21, 2026
@sharkdp sharkdp enabled auto-merge (squash) May 21, 2026 13:37
@sharkdp sharkdp merged commit c714e84 into main May 21, 2026
50 of 51 checks passed
@sharkdp sharkdp deleted the codex/mdtest-union-parameters branch May 21, 2026 13:39
thejchap pushed a commit to thejchap/ruff that referenced this pull request May 23, 2026
Remember when we wrote `x = 1 if flag else None` because we couldn't
infer types from annotated parameters and/or couldn't understand union
type annotations? This PR modernizes our mdtests to simply use annotated
function parameters in those cases (I manually rejected some rewrites
when the new style was less clear, for example when the generated union
type itself was hard to spell).

The motivation for this is to set a better precedent for agents, as I've
seen them repeating that `x if flag else y` pattern, which is really
unnecessary, longer and harder to read in most cases.
anishgirianish pushed a commit to anishgirianish/ruff that referenced this pull request May 28, 2026
Remember when we wrote `x = 1 if flag else None` because we couldn't
infer types from annotated parameters and/or couldn't understand union
type annotations? This PR modernizes our mdtests to simply use annotated
function parameters in those cases (I manually rejected some rewrites
when the new style was less clear, for example when the generated union
type itself was hard to spell).

The motivation for this is to set a better precedent for agents, as I've
seen them repeating that `x if flag else y` pattern, which is really
unnecessary, longer and harder to read in most cases.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

testing Related to testing Ruff itself ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants