Skip to content

[ty] resolve union-likes in emitting union attribute errors#24263

Merged
carljm merged 1 commit intomainfrom
cjm/aliasunion
Mar 28, 2026
Merged

[ty] resolve union-likes in emitting union attribute errors#24263
carljm merged 1 commit intomainfrom
cjm/aliasunion

Conversation

@carljm
Copy link
Copy Markdown
Contributor

@carljm carljm commented Mar 28, 2026

Summary

Fixes astral-sh/ty#3161

When emitting attribute errors on a union, make sure we descend into union-likes (type aliases to unions, typevars) as well.

Test Plan

Added mdtest.

@carljm carljm added the ty Multi-file analysis & type inference label Mar 28, 2026
@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot bot commented Mar 28, 2026

Typing conformance results

No changes detected ✅

Current numbers
The percentage of diagnostics emitted that were expected errors held steady at 86.59%. The percentage of expected errors that received a diagnostic held steady at 80.96%. The number of fully passing files held steady at 68/132.

@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot bot commented Mar 28, 2026

Memory usage report

Memory usage unchanged ✅

@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot bot commented Mar 28, 2026

ecosystem-analyzer results

Lint rule Added Removed Changed
invalid-await 0 40 0
unresolved-attribute 0 0 7
invalid-return-type 0 1 0
Total 0 41 7

Changes in flaky projects detected. Raw diff output excludes flaky projects; see the HTML report for details.

Raw diff:

scipy (https://github.com/scipy/scipy)
- scipy/spatial/transform/_rigid_transform.py:1400:25 error[unresolved-attribute] Attribute `dtype` is not defined on `int`, `slice[Any, Any, Any]`, `EllipsisType`, `None` in union `int | slice[Any, Any, Any] | EllipsisType | None | ArrayLike`
+ scipy/spatial/transform/_rigid_transform.py:1400:25 error[unresolved-attribute] Attribute `dtype` is not defined on `int`, `slice[Any, Any, Any]`, `EllipsisType`, `None`, `Buffer`, `_SupportsArray[dtype[Any]]`, `_NestedSequence[_SupportsArray[dtype[Any]]]`, `float`, `complex`, `str`, `_NestedSequence[int | float | complex | bytes | str]` in union `int | slice[Any, Any, Any] | EllipsisType | None | ArrayLike`
- scipy/spatial/transform/_rigid_transform.py:1402:36 error[unresolved-attribute] Attribute `dtype` is not defined on `int`, `slice[Any, Any, Any]`, `EllipsisType`, `None` in union `int | slice[Any, Any, Any] | EllipsisType | None | ArrayLike`
+ scipy/spatial/transform/_rigid_transform.py:1402:36 error[unresolved-attribute] Attribute `dtype` is not defined on `int`, `slice[Any, Any, Any]`, `EllipsisType`, `None`, `Buffer`, `_SupportsArray[dtype[Any]]`, `_NestedSequence[_SupportsArray[dtype[Any]]]`, `float`, `complex`, `str`, `_NestedSequence[int | float | complex | bytes | str]` in union `int | slice[Any, Any, Any] | EllipsisType | None | ArrayLike`
- scipy/spatial/transform/_rotation_xp.py:421:8 error[unresolved-attribute] Attribute `shape` is not defined on `ArrayLike` in union `ArrayLike`
+ scipy/spatial/transform/_rotation_xp.py:421:8 error[unresolved-attribute] Attribute `shape` is not defined on `Buffer`, `_SupportsArray[dtype[Any]]`, `_NestedSequence[_SupportsArray[dtype[Any]]]`, `int`, `float`, `complex`, `str`, `_NestedSequence[int | float | complex | bytes | str]` in union `ArrayLike`
- scipy/spatial/transform/_rotation_xp.py:422:50 error[unresolved-attribute] Attribute `shape` is not defined on `ArrayLike` in union `ArrayLike`
+ scipy/spatial/transform/_rotation_xp.py:422:50 error[unresolved-attribute] Attribute `shape` is not defined on `Buffer`, `_SupportsArray[dtype[Any]]`, `_NestedSequence[_SupportsArray[dtype[Any]]]`, `int`, `float`, `complex`, `str`, `_NestedSequence[int | float | complex | bytes | str]` in union `ArrayLike`
- scipy/spatial/transform/_rotation_xp.py:423:8 error[unresolved-attribute] Attribute `shape` is not defined on `ArrayLike` in union `ArrayLike`
+ scipy/spatial/transform/_rotation_xp.py:423:8 error[unresolved-attribute] Attribute `shape` is not defined on `Buffer`, `_SupportsArray[dtype[Any]]`, `_NestedSequence[_SupportsArray[dtype[Any]]]`, `int`, `float`, `complex`, `str`, `_NestedSequence[int | float | complex | bytes | str]` in union `ArrayLike`
- scipy/spatial/transform/_rotation_xp.py:425:26 error[unresolved-attribute] Attribute `shape` is not defined on `ArrayLike` in union `ArrayLike`
+ scipy/spatial/transform/_rotation_xp.py:425:26 error[unresolved-attribute] Attribute `shape` is not defined on `Buffer`, `_SupportsArray[dtype[Any]]`, `_NestedSequence[_SupportsArray[dtype[Any]]]`, `int`, `float`, `complex`, `str`, `_NestedSequence[int | float | complex | bytes | str]` in union `ArrayLike`
- scipy/spatial/transform/_rotation_xp.py:427:66 error[unresolved-attribute] Attribute `shape` is not defined on `ArrayLike` in union `ArrayLike`
+ scipy/spatial/transform/_rotation_xp.py:427:66 error[unresolved-attribute] Attribute `shape` is not defined on `Buffer`, `_SupportsArray[dtype[Any]]`, `_NestedSequence[_SupportsArray[dtype[Any]]]`, `int`, `float`, `complex`, `str`, `_NestedSequence[int | float | complex | bytes | str]` in union `ArrayLike`

Full report with detailed diff (timing results)

@carljm carljm marked this pull request as ready for review March 28, 2026 00:47
@carljm carljm merged commit 62e1a60 into main Mar 28, 2026
49 checks passed
@carljm carljm deleted the cjm/aliasunion branch March 28, 2026 01:48
carljm added a commit that referenced this pull request Mar 31, 2026
* main: (40 commits)
  [ty] resolve union-likes in emitting union attribute errors (#24263)
  [ty] Improve support for `Callable` type context (#23888)
  [ty] Propagate type context through `await` expressions (#24256)
  [`pyflakes`] Flag annotated variable redeclarations as `F811` in preview mode (#24244)
  [ty] Preserve `Divergent` when materializing recursive aliases (#24245)
  Fix W391 fixes for consecutive empty notebook cells (#24236)
  [flake8-bugbear] Clarify RUF071 fix safety for non-path string comparisons (#24149)
  [ty] Ban type qualifiers in PEP-695 type aliases (#24242)
  [ty] Include keyword-prefixed symbols in completions for attributes (#24232)
  [ty] Add tests for TypedDict method overloads on unions (#24230)
  [ty] report unused bindings as unnecessary hint diagnostics (#23305)
  Remove unused `non_root` variable (#24238)
  Extend F507 to flag %-format strings with zero placeholders (#24215)
  [`flake8-simplify`] Suppress `SIM105` for `except*` before Python 3.12 (#23869)
  Ignore pre-initialization references in SIM113 (#24235)
  Parenthesize expression in RUF050 fix (#24234)
  Publish playgrounds using the `release-playground` environment (#24223)
  [ty] Fix instance-attribute lookup in methods of protocol classes (#24213)
  [ty] Used shared expression cache during generic call inference (#24219)
  [ty] make `Type::BoundMethod` include instances of same-named methods bound to a subclass (#24039)
  ...
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.

Looping through list of aliased union causes potentially-missing members to be available

3 participants