experimental-inspect: dedup union members - #6273
Open
jonasdedden wants to merge 2 commits into
Open
Conversation
`#[derive(FromPyObject)]` on an enum builds its `INPUT_TYPE` by `reduce`-ing
the variants' own input types with `|`. Two variants overlapping is normal, and
the result repeats the overlap:
enum FileInput { Path(PathBuf), Name(String), FileLike(PyFileLikeObject) }
// file: str | os.PathLike[str] | str | Incomplete
The macro cannot collapse that — at expansion time the members are unresolved
associated constants, and it has no idea `PathBuf` contributes a `str` arm. By
the time `pyo3-introspection` renders the union it is a plain expression tree,
so this flattens the `|` chain and drops structurally equal repeats, keeping
first-occurrence order.
The same match arm also wrote `buffer.push(' ')` before the `|` and nothing
after it, so every union came out as `str |None`. That is invisible in this
repository because `nox -s test-introspection` pipes the stubs through
`ruff format` before comparing them to the checked-in fixtures, but it is what
the raw output looks like to anyone who does not format it.
experimental-inspect dedup union membersexperimental-inspect: dedup union members
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#[derive(FromPyObject)]on an enum builds itsINPUT_TYPEbyreduce-ing the variants' own input types with|. Two ariants overlapping is normal, and the result repeats the overlap:The macro cannot collapse that - at expansion time the members are unresolved associated constants, and it has no idea
PathBufcontributes astrarm. By the timepyo3-introspectionrenders the union it is a plain expression tree, so this flattens the|chain and drops structurally equal repeats, keeping first-occurrence order.Additional formatting improvement: The same match arm also wrote
buffer.push(' ')before the|and nothing after it, so every union came out asstr |None. That is invisible in this repository becausenox -s test-introspectionpipes the stubs throughruff formatbefore comparing them to the checked-in fixtures, but it is what the raw output looks like to anyone who does not format it.