[ty] ensure union normalization really normalizes by carljm · Pull Request #20147 · astral-sh/ruff (original) (raw)

@carljm

@carljm added the ty

Multi-file analysis & type inference

label

Aug 29, 2025

@carljm carljm marked this pull request as ready for review

August 29, 2025 02:53

AlexWaygood

@carljm @AlexWaygood

Co-authored-by: Alex Waygood Alex.Waygood@Gmail.com

carljm

@carljm

@carljm carljm deleted the cjm/union-norm branch

August 29, 2025 16:02

dcreager added a commit that referenced this pull request

Sep 2, 2025

@dcreager

second-ed pushed a commit to second-ed/ruff that referenced this pull request

Sep 9, 2025

Summary

Now that we have Type::TypeAlias, which can wrap a union, and the possibility of unions including non-unpacked type aliases (which is necessary to support recursive type aliases), we can no longer assume in UnionType::normalized_impl that normalizing each element of an existing union will result in a set of elements that we can order and then place raw into UnionType to create a normalized union. It's now possible for those elements to themselves include union types (unpacked from an alias). So instead, we need to feed those elements into the full UnionBuilder (with alias-unpacking turned on) to flatten/normalize them, and then order them.

Test Plan

Added mdtest.


Co-authored-by: Alex Waygood Alex.Waygood@Gmail.com

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})