Skip to content

[ty] treat union-bound typevars like unions for possibly-missing-attribute#25561

Merged
carljm merged 2 commits into
mainfrom
cjm/fix-union-typevar-attribute-error
Jun 3, 2026
Merged

[ty] treat union-bound typevars like unions for possibly-missing-attribute#25561
carljm merged 2 commits into
mainfrom
cjm/fix-union-typevar-attribute-error

Conversation

@carljm

@carljm carljm commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Treat bounded TypeVars like their upper bound when deciding whether a possibly-missing-attribute should be promoted to unresolved-attribute. We missed this case in #23042, and then we disabled possibly-missing-attribute by default, so on main we are silent by default when accessing an attribute that is missing on some elements of a typevar upper-bound union.

Testing

Added mdtest.

@astral-sh-bot astral-sh-bot Bot added the ty Multi-file analysis & type inference label Jun 2, 2026
@astral-sh-bot

astral-sh-bot Bot commented Jun 2, 2026

Copy link
Copy Markdown

Typing conformance results

No changes detected ✅

Current numbers
The percentage of diagnostics emitted that were expected errors held steady at 91.94%. The percentage of expected errors that received a diagnostic held steady at 87.09%. The number of fully passing files held steady at 92/134.

@astral-sh-bot

astral-sh-bot Bot commented Jun 2, 2026

Copy link
Copy Markdown

Memory usage report

Memory usage unchanged ✅

@astral-sh-bot

astral-sh-bot Bot commented Jun 2, 2026

Copy link
Copy Markdown

ecosystem-analyzer results

Lint rule Added Removed Changed
possibly-missing-attribute 0 1 0
unresolved-attribute 1 0 0
Total 1 1 0

Flaky changes detected. This PR summary excludes flaky changes; see the HTML report for details.

Raw diff:

core (https://github.com/home-assistant/core)
- homeassistant/components/sonos/helpers.py:82:42 warning[possibly-missing-attribute] Attribute `soco` may be missing on object of type `_T@soco_error`
+ homeassistant/components/sonos/helpers.py:82:42 error[unresolved-attribute] Attribute `soco` is not defined on `SonosHouseholdCoordinator` in union `_SonosEntitiesType`

Full report with detailed diff (timing results)

@AlexWaygood AlexWaygood added the bug Something isn't working label Jun 2, 2026
@carljm carljm marked this pull request as ready for review June 2, 2026 23:26
@astral-sh-bot astral-sh-bot Bot requested a review from dhruvmanila June 2, 2026 23:26

@AlexWaygood AlexWaygood left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What error code do we use if you try to access .hex() on an instance of a NewType of float?

@carljm

carljm commented Jun 3, 2026

Copy link
Copy Markdown
Contributor Author

What error code do we use if you try to access .hex() on an instance of a NewType of float?

unresolved-attribute (correctly), because as_union_like already handles NewType.

@carljm carljm merged commit 2965c98 into main Jun 3, 2026
59 checks passed
@carljm carljm deleted the cjm/fix-union-typevar-attribute-error branch June 3, 2026 00:02
carljm added a commit that referenced this pull request Jun 3, 2026
* origin/main: (114 commits)
  [ty] Detect disjointness due to incompatible generic specializations (#24822)
  Update Rust crate memchr to v2.8.1 (#25586)
  [ty] Reject Self in type aliases (#25529)
  Update Rust crate log to v0.4.30 (#25572)
  Update Rust crate mimalloc to v0.1.52 (#25573)
  Update Rust crate similar to v3.1.1 (#25575)
  Update docker/setup-buildx-action action to v4.1.0 (#25580)
  Update docker/metadata-action action to v6.1.0 (#25579)
  Update docker/login-action action to v4.2.0 (#25578)
  Update docker/build-push-action action to v7.2.0 (#25577)
  Update taiki-e/install-action action to v2.79.9 (#25576)
  Update Rust crate serde_json to v1.0.150 (#25574)
  Update Rust crate assert_fs to v1.1.4 (#25570)
  Update prek dependencies (#25569)
  Update dependency ruff to v0.15.15 (#25568)
  Update dependency pyright to v1.1.410 (#25566)
  Update dependency astral-sh/uv to v0.11.18 (#25565)
  [ty] don't needlessly disambiguate same type alias (#25563)
  [ty] fix variance inference for nested type aliases (#25567)
  [ty] treat union-bound typevars like unions for possibly-missing-attribute (#25561)
  ...

# Conflicts:
#	crates/ty_python_semantic/src/types/class.rs
#	crates/ty_python_semantic/src/types/generics.rs
#	crates/ty_python_semantic/src/types/type_alias.rs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants