You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In expression.rs, we have some logic to avoid checking nested Union operators, since our Union checks operate recursively (and so re-checking nested Union operators leads to duplicate diagnostics).
These checks don't quite work in .pyi files due to the way we process deferred nodes. We don't store the current expression stack when snapshotting the SemanticModel, because that would require us to store all expressions in an IndexVec. This is a known source of bugs.
We can store the expressions in an IndexVec, like we do for statements, but it will definitely hurt performance and increase memory usage.
As an example, if this is put in a .pyi file:
fromtypingimportUnionUnion[int, Union[int, int]]
You'll hit duplicate violations:
foo.pyi:3:22: PYI016 Duplicate union member `int`
foo.pyi:3:27: PYI016 Duplicate union member `int`
foo.pyi:3:27: PYI016 Duplicate union member `int`
The text was updated successfully, but these errors were encountered:
#6399)
## Summary
We have some logic in the expression analyzer method to avoid
re-checking the inner `Union` in `Union[Union[...]]`, since the methods
that analyze `Union` expressions already recurse. Elsewhere, we have
logic to avoid re-checking the inner `|` in `int | (int | str)`, for the
same reason.
This PR unifies that logic into a single method _and_ ensures that, just
as we recurse over both `Union` and `|`, we also detect that we're in
_either_ kind of nested union.
Closes#6285.
## Test Plan
Added some new snapshots.
durumu
pushed a commit
to durumu/ruff
that referenced
this issue
Aug 12, 2023
astral-sh#6399)
## Summary
We have some logic in the expression analyzer method to avoid
re-checking the inner `Union` in `Union[Union[...]]`, since the methods
that analyze `Union` expressions already recurse. Elsewhere, we have
logic to avoid re-checking the inner `|` in `int | (int | str)`, for the
same reason.
This PR unifies that logic into a single method _and_ ensures that, just
as we recurse over both `Union` and `|`, we also detect that we're in
_either_ kind of nested union.
Closesastral-sh#6285.
## Test Plan
Added some new snapshots.
In
expression.rs
, we have some logic to avoid checking nestedUnion
operators, since ourUnion
checks operate recursively (and so re-checking nestedUnion
operators leads to duplicate diagnostics).These checks don't quite work in
.pyi
files due to the way we process deferred nodes. We don't store the current expression stack when snapshotting theSemanticModel
, because that would require us to store all expressions in anIndexVec
. This is a known source of bugs.We can store the expressions in an
IndexVec
, like we do for statements, but it will definitely hurt performance and increase memory usage.As an example, if this is put in a
.pyi
file:You'll hit duplicate violations:
The text was updated successfully, but these errors were encountered: