Skip to content

[ty] Add materialization to Divergent type#24255

Merged
charliermarsh merged 2 commits intomainfrom
charlie/divergent-two
Mar 30, 2026
Merged

[ty] Add materialization to Divergent type#24255
charliermarsh merged 2 commits intomainfrom
charlie/divergent-two

Conversation

@charliermarsh
Copy link
Copy Markdown
Member

@charliermarsh charliermarsh commented Mar 27, 2026

Summary

This PR follows #24245 (comment) such that we preserve the top or bottom materialization on Divergent materializing recursive types.

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

astral-sh-bot bot commented Mar 27, 2026

Typing conformance results

No changes detected ✅

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

@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot bot commented Mar 27, 2026

Memory usage report

Memory usage unchanged ✅

@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot bot commented Mar 27, 2026

ecosystem-analyzer results

Lint rule Added Removed Changed
invalid-await 40 0 0
index-out-of-bounds 0 1 0
invalid-assignment 0 1 0
invalid-return-type 1 0 0
Total 41 2 0

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

Raw diff:

rotki (https://github.com/rotki/rotki)
- rotkehlchen/exchanges/coinbase.py:466:40 error[invalid-assignment] Object of type `dict[str, list[dict[Unknown, Unknown]]]` is not assignable to `defaultdict[str, list[dict[Unknown, Unknown]]]`

scipy (https://github.com/scipy/scipy)
- scipy/interpolate/_interpolate.py:2264:56 error[index-out-of-bounds] Index 1 is out of bounds for tuple `tuple[int]` with length 1

Full report with detailed diff (timing results)

@charliermarsh charliermarsh force-pushed the charlie/divergent-two branch from 046d697 to 4cfcae6 Compare March 28, 2026 00:51
@charliermarsh charliermarsh marked this pull request as ready for review March 28, 2026 00:55
@carljm carljm assigned carljm and unassigned dcreager Mar 28, 2026
Type::Dynamic(_) | Type::Divergent(_) => *self,
Type::Dynamic(_) => *self,

Type::Divergent(divergent) => match divergent.materialization_kind() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This behavior looks good, but IntersectionBuilder doesn't do the same (it will add a materialized divergent as just a normal negated element). This could break all_negated_types_identical_to_intersection_with_single_negated_element property test (if property tests included Divergent, which they don't currently -- but it might be useful validation of this stack to add both materialized and non-materialized Divergent to the property tests, and run them.) I think IntersectionBuilder should gain some recognition of materialized Divergent to fix this.

source: Type<'db>,
target: Type<'db>,
) -> ConstraintSet<'db, 'c> {
if let Some(source) = source.materialized_divergent_fallback() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Are there other places that need similar handling to this? Type::subscript? try_upcast_to_callable_with_policy? Member access?

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Mar 30, 2026

Merging this PR will improve performance by 7.47%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 1 improved benchmark
✅ 46 untouched benchmarks
⏩ 60 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation ty_micro[many_enum_members_2] 172.6 ms 160.6 ms +7.47%

Comparing charlie/divergent-two (9f85c4a) with main (e871de4)

Open in CodSpeed

Footnotes

  1. 60 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@charliermarsh charliermarsh force-pushed the charlie/divergent-two branch from af77a5c to 3e9746b Compare March 30, 2026 15:18
@charliermarsh charliermarsh force-pushed the charlie/divergent-two branch from 3e9746b to eb89858 Compare March 30, 2026 17:25
@AlexWaygood AlexWaygood removed their request for review March 30, 2026 17:26
Base automatically changed from charlie/divergent to main March 30, 2026 19:17
@charliermarsh charliermarsh force-pushed the charlie/divergent-two branch from eb89858 to fb70452 Compare March 30, 2026 19:17
@charliermarsh charliermarsh force-pushed the charlie/divergent-two branch from fb70452 to 9f85c4a Compare March 30, 2026 19:27
@charliermarsh charliermarsh merged commit ff4b4cb into main Mar 30, 2026
51 checks passed
@charliermarsh charliermarsh deleted the charlie/divergent-two branch March 30, 2026 19:54
carljm added a commit that referenced this pull request Mar 31, 2026
* main: (35 commits)
  Store definition indexes as u32 (#24307)
  Avoid re-using symbol in RUF024 fix (#24316)
  [ty] Add materialization to `Divergent` type (#24255)
  [ty] Make `Divergent` a top-level type variant (#24252)
  [ty] Fix nested global and nonlocal lookups through forwarding scopes (#24279)
  Fetch the cargo-dist binary directly instead of using the installer (#24258)
  [ty] Fix panic on `list[Annotated[()]]` (#24303)
  Don't measure the AST deallocation time in parser benchmarks (#24301)
  Enable CodSpeed's memory benchmarks for simulation benchmarks (#24298)
  Upgrade imara-diff to 0.2.0 (#24299)
  [ty] Represent `InitVar` as a special form internally, not a class (#24248)
  `RUF067`: Allow dunder-named assignments in non-strict mode
  [`pyupgrade`] UP018 should detect more unnecessarily wrapped literals (UP018) (#24093)
  [ty] Remove unused `system.glob` method (#24300)
  [ty] Reject functional TypedDict with mismatched name (#24295)
  Update Rust crate arc-swap to v1.9.0 (#24292)
  [ty] Remove unused `@Todo(Functional TypedDicts)` (#24297)
  Update CodSpeedHQ/action action to v4.12.1 (#24290)
  Update taiki-e/install-action action to v2.69.6 (#24293)
  Update Rust crate toml to v1.0.7 (#24289)
  ...
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.

3 participants