Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[ty] Fix bound TypeVar default cycle recovery#26124

Merged
MichaReiser merged 6 commits into
mainfrom
micha/fix-bound-typevar-default-cycle
Jun 18, 2026
Merged

[ty] Fix bound TypeVar default cycle recovery#26124
MichaReiser merged 6 commits into
mainfrom
micha/fix-bound-typevar-default-cycle

Conversation

@MichaReiser

Copy link
Copy Markdown
Member

Summary

Preserve bound TypeVar defaults during Salsa fixed-point cycle recovery instead of replacing provisional values with None. This prevents query-order-dependent diagnostics in cyclic generic definitions and fixes astral-sh/ty#3804.

Test Plan

Testing: added regression coverage and ran focused semantic tests, Clippy, and repository hooks.

@astral-sh-bot astral-sh-bot Bot added the ty Multi-file analysis & type inference label Jun 18, 2026
@MichaReiser MichaReiser added the bug Something isn't working label Jun 18, 2026
@astral-sh-bot

astral-sh-bot Bot commented Jun 18, 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 94.37%. The percentage of expected errors that received a diagnostic held steady at 89.00%. The number of fully passing files held steady at 94/134.

@astral-sh-bot

astral-sh-bot Bot commented Jun 18, 2026

Copy link
Copy Markdown

Memory usage report

Memory usage unchanged ✅

@astral-sh-bot

astral-sh-bot Bot commented Jun 18, 2026

Copy link
Copy Markdown

ecosystem-analyzer results

Lint rule Added Removed Changed
unresolved-attribute 0 0 21
invalid-assignment 0 0 2
invalid-argument-type 0 0 1
Total 0 0 24

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

Raw diff (24 changes)
boostedblob (https://github.com/hauntsaninja/boostedblob)
- boostedblob/listing.py:402:14 error[unresolved-attribute] Object of type `Element[Unknown]` has no attribute `iterchildren`
+ boostedblob/listing.py:402:14 error[unresolved-attribute] Object of type `Element[str]` has no attribute `iterchildren`

cloud-init (https://github.com/canonical/cloud-init)
- cloudinit/sources/helpers/azure.py:518:32 error[unresolved-attribute] Attribute `text` is not defined on `None` in union `Element[Unknown] | None`
+ cloudinit/sources/helpers/azure.py:518:32 error[unresolved-attribute] Attribute `text` is not defined on `None` in union `Element[str] | None`

dd-trace-py (https://github.com/DataDog/dd-trace-py)
- tests/contrib/pytest/test_pytest_atr.py:337:16 error[unresolved-attribute] Attribute `attrib` is not defined on `None` in union `Element[Unknown] | None`
+ tests/contrib/pytest/test_pytest_atr.py:337:16 error[unresolved-attribute] Attribute `attrib` is not defined on `None` in union `Element[str] | None`
- tests/contrib/pytest/test_pytest_atr.py:338:16 error[unresolved-attribute] Attribute `attrib` is not defined on `None` in union `Element[Unknown] | None`
+ tests/contrib/pytest/test_pytest_atr.py:338:16 error[unresolved-attribute] Attribute `attrib` is not defined on `None` in union `Element[str] | None`
- tests/contrib/pytest/test_pytest_atr.py:339:16 error[unresolved-attribute] Attribute `attrib` is not defined on `None` in union `Element[Unknown] | None`
+ tests/contrib/pytest/test_pytest_atr.py:339:16 error[unresolved-attribute] Attribute `attrib` is not defined on `None` in union `Element[str] | None`
- tests/contrib/pytest/test_pytest_atr.py:340:16 error[unresolved-attribute] Attribute `attrib` is not defined on `None` in union `Element[Unknown] | None`
+ tests/contrib/pytest/test_pytest_atr.py:340:16 error[unresolved-attribute] Attribute `attrib` is not defined on `None` in union `Element[str] | None`
- tests/contrib/pytest/test_pytest_attempt_to_fix.py:259:16 error[unresolved-attribute] Attribute `attrib` is not defined on `None` in union `Element[Unknown] | None`
+ tests/contrib/pytest/test_pytest_attempt_to_fix.py:259:16 error[unresolved-attribute] Attribute `attrib` is not defined on `None` in union `Element[str] | None`
- tests/contrib/pytest/test_pytest_attempt_to_fix.py:260:16 error[unresolved-attribute] Attribute `attrib` is not defined on `None` in union `Element[Unknown] | None`
+ tests/contrib/pytest/test_pytest_attempt_to_fix.py:260:16 error[unresolved-attribute] Attribute `attrib` is not defined on `None` in union `Element[str] | None`
- tests/contrib/pytest/test_pytest_attempt_to_fix.py:261:16 error[unresolved-attribute] Attribute `attrib` is not defined on `None` in union `Element[Unknown] | None`
+ tests/contrib/pytest/test_pytest_attempt_to_fix.py:261:16 error[unresolved-attribute] Attribute `attrib` is not defined on `None` in union `Element[str] | None`
- tests/contrib/pytest/test_pytest_attempt_to_fix.py:262:16 error[unresolved-attribute] Attribute `attrib` is not defined on `None` in union `Element[Unknown] | None`
+ tests/contrib/pytest/test_pytest_attempt_to_fix.py:262:16 error[unresolved-attribute] Attribute `attrib` is not defined on `None` in union `Element[str] | None`
- tests/contrib/pytest/test_pytest_attempt_to_fix.py:271:16 error[unresolved-attribute] Attribute `attrib` is not defined on `None` in union `Element[Unknown] | None`
+ tests/contrib/pytest/test_pytest_attempt_to_fix.py:271:16 error[unresolved-attribute] Attribute `attrib` is not defined on `None` in union `Element[str] | None`
- tests/contrib/pytest/test_pytest_attempt_to_fix.py:272:16 error[unresolved-attribute] Attribute `attrib` is not defined on `None` in union `Element[Unknown] | None`
+ tests/contrib/pytest/test_pytest_attempt_to_fix.py:272:16 error[unresolved-attribute] Attribute `attrib` is not defined on `None` in union `Element[str] | None`
- tests/contrib/pytest/test_pytest_attempt_to_fix.py:273:16 error[unresolved-attribute] Attribute `attrib` is not defined on `None` in union `Element[Unknown] | None`
+ tests/contrib/pytest/test_pytest_attempt_to_fix.py:273:16 error[unresolved-attribute] Attribute `attrib` is not defined on `None` in union `Element[str] | None`
- tests/contrib/pytest/test_pytest_attempt_to_fix.py:274:16 error[unresolved-attribute] Attribute `attrib` is not defined on `None` in union `Element[Unknown] | None`
+ tests/contrib/pytest/test_pytest_attempt_to_fix.py:274:16 error[unresolved-attribute] Attribute `attrib` is not defined on `None` in union `Element[str] | None`
- tests/contrib/pytest/test_pytest_efd.py:517:16 error[unresolved-attribute] Attribute `attrib` is not defined on `None` in union `Element[Unknown] | None`
+ tests/contrib/pytest/test_pytest_efd.py:517:16 error[unresolved-attribute] Attribute `attrib` is not defined on `None` in union `Element[str] | None`
- tests/contrib/pytest/test_pytest_efd.py:518:16 error[unresolved-attribute] Attribute `attrib` is not defined on `None` in union `Element[Unknown] | None`
+ tests/contrib/pytest/test_pytest_efd.py:518:16 error[unresolved-attribute] Attribute `attrib` is not defined on `None` in union `Element[str] | None`

meson (https://github.com/mesonbuild/meson)
- mesonbuild/mtest.py:1132:17 error[invalid-assignment] Object of type `ElementTree[Element[Unknown]]` is not assignable to attribute `junit` of type `ElementTree[Element[Unknown] | None] | None`
+ mesonbuild/mtest.py:1132:17 error[invalid-assignment] Object of type `ElementTree[Element[str]]` is not assignable to attribute `junit` of type `ElementTree[Element[str] | None] | None`
- run_project_tests.py:1290:38 error[invalid-argument-type] Argument to function `SubElement` is incorrect: Expected `Element[Any]`, found `Unknown | Element[Unknown] | None`
+ run_project_tests.py:1290:38 error[invalid-argument-type] Argument to function `SubElement` is incorrect: Expected `Element[Any]`, found `Unknown | Element[str] | None`

pandas (https://github.com/pandas-dev/pandas)
- pandas/io/xml.py:483:21 error[unresolved-attribute] Attribute `findall` is not defined on `None` in union `Element[Unknown] | Unknown | None`
+ pandas/io/xml.py:483:21 error[unresolved-attribute] Attribute `findall` is not defined on `None` in union `Element[str] | Unknown | None`
- pandas/io/xml.py:516:26 error[unresolved-attribute] Attribute `find` is not defined on `None` in union `Element[Unknown] | Unknown | None`
+ pandas/io/xml.py:516:26 error[unresolved-attribute] Attribute `find` is not defined on `None` in union `Element[str] | Unknown | None`
- pandas/io/xml.py:600:17 error[unresolved-attribute] Attribute `xpath` is not defined on `Element[Unknown]`, `None` in union `Element[Unknown] | Unknown | None`
+ pandas/io/xml.py:600:17 error[unresolved-attribute] Attribute `xpath` is not defined on `Element[str]`, `None` in union `Element[str] | Unknown | None`
- pandas/io/xml.py:626:28 error[unresolved-attribute] Attribute `xpath` is not defined on `Element[Unknown]`, `None` in union `Element[Unknown] | Unknown | None`
+ pandas/io/xml.py:626:28 error[unresolved-attribute] Attribute `xpath` is not defined on `Element[str]`, `None` in union `Element[str] | Unknown | None`

pytest (https://github.com/pytest-dev/pytest)
- src/_pytest/junitxml.py:256:9 error[invalid-assignment] Object of type `() -> Element[Unknown]` is not assignable to attribute `to_xml` of type `def to_xml(self) -> Element[Unknown]`
+ src/_pytest/junitxml.py:256:9 error[invalid-assignment] Object of type `() -> Element[str]` is not assignable to attribute `to_xml` of type `def to_xml(self) -> Element[str]`

spack (https://github.com/spack/spack)
- lib/spack/spack/test/conftest.py:1917:16 error[unresolved-attribute] Attribute `get` is not defined on `None` in union `Element[Unknown] | None`
+ lib/spack/spack/test/conftest.py:1917:16 error[unresolved-attribute] Attribute `get` is not defined on `None` in union `Element[str] | None`

Full report with detailed diff (timing results)

Comment thread crates/ty_python_semantic/src/types/typevar.rs Outdated
return false;
}

if let Some(specialization) = type_alias.specialization(state.db) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is needed to prevent a stack overflow and looks very similar to what was added in #23652. I'm obviously way out of my depth here, but it doesn't look unreasonable :)

@MichaReiser MichaReiser marked this pull request as ready for review June 18, 2026 11:50
@MichaReiser MichaReiser requested a review from a team as a code owner June 18, 2026 11:50
@MichaReiser

Copy link
Copy Markdown
Member Author

The ecosystem report is clean: 32 changes, all expected, with no added diagnostics or crashes. Detailed report, successful Actions run.

  • 24 diagnostic changes across seven projects come from preserving typeshed’s default for bare Element, improving Element[Unknown] to Element[str].
  • In steam.py, five false invalid-type-arguments errors and two related unused-ignore warnings disappear.
  • One remaining steam.py diagnostic becomes more precise by losing spurious Unknown intersections.

@MichaReiser MichaReiser marked this pull request as draft June 18, 2026 12:15
@MichaReiser MichaReiser marked this pull request as ready for review June 18, 2026 12:31
@MichaReiser

Copy link
Copy Markdown
Member Author

@charliermarsh would you mind taking another look. I made a few more changes.

@MichaReiser MichaReiser merged commit ef0fb8f into main Jun 18, 2026
60 checks passed
@MichaReiser MichaReiser deleted the micha/fix-bound-typevar-default-cycle branch June 18, 2026 15:17
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.

Non deterministic output for recursive type var default

2 participants