Skip to content

Conversation

@carljm
Copy link
Contributor

@carljm carljm commented Dec 11, 2025

Partially addresses astral-sh/ty#1732

Summary

Don't union the previous type in fixpoint iteration if the previous type contains a Divergent from the current cycle and the latest type does not. The theory here, as outlined by @mtshiba at astral-sh/ty#1732 (comment), is that oscillation can't occur by removing and then reintroducing a Divergent type repeatedly, since Divergent types are only introduced at the start of fixpoint iteration.

Test Plan

Removes a Divergent type from the added mdtest, doesn't otherwise regress any tests.

@carljm carljm added the ty Multi-file analysis & type inference label Dec 11, 2025
@astral-sh-bot
Copy link

astral-sh-bot bot commented Dec 11, 2025

Diagnostic diff on typing conformance tests

No changes detected when running ty on typing conformance tests ✅

@carljm carljm force-pushed the cjm/nodiv branch 2 times, most recently from a697b63 to 9d17c17 Compare December 11, 2025 00:42
@astral-sh-bot
Copy link

astral-sh-bot bot commented Dec 11, 2025

mypy_primer results

Changes were detected when running on open source projects
spack (https://github.com/spack/spack)
- lib/spack/spack/mirrors/mirror.py:114:16: error[invalid-return-type] Return type does not match returned value: expected `bool`, found `Literal[True] | Unknown | str | Divergent`
+ lib/spack/spack/mirrors/mirror.py:114:16: error[invalid-return-type] Return type does not match returned value: expected `bool`, found `Literal[True] | Unknown | str`
- lib/spack/spack/mirrors/mirror.py:120:16: error[invalid-return-type] Return type does not match returned value: expected `bool`, found `Unknown | str | Divergent`
+ lib/spack/spack/mirrors/mirror.py:120:16: error[invalid-return-type] Return type does not match returned value: expected `bool`, found `Unknown | str`
- lib/spack/spack/mirrors/mirror.py:263:45: error[invalid-argument-type] Argument to bound method `_update_connection_dict` is incorrect: Expected `dict[Unknown, Unknown]`, found `@Todo | str | Divergent`
+ lib/spack/spack/mirrors/mirror.py:263:45: error[invalid-argument-type] Argument to bound method `_update_connection_dict` is incorrect: Expected `dict[Unknown, Unknown]`, found `@Todo | str`

setuptools (https://github.com/pypa/setuptools)
- setuptools/_distutils/command/build_ext.py:270:23: warning[possibly-missing-attribute] Attribute `split` may be missing on object of type `(Unknown & ~AlwaysFalsy) | (list[tuple[Unknown, str] | Unknown] & ~AlwaysFalsy) | (list[Divergent] & ~AlwaysFalsy)`
+ setuptools/_distutils/command/build_ext.py:270:23: warning[possibly-missing-attribute] Attribute `split` may be missing on object of type `(Unknown & ~AlwaysFalsy) | (list[tuple[Unknown, str] | Unknown] & ~AlwaysFalsy)`
- setuptools/_distutils/command/sdist.py:372:58: error[invalid-argument-type] Argument to function `__new__` is incorrect: Expected `str | Buffer | SupportsInt | SupportsIndex | SupportsTrunc`, found `Unknown | Literal[0] | None | list[Unknown | int | None] | list[Divergent]`
+ setuptools/_distutils/command/sdist.py:372:58: error[invalid-argument-type] Argument to function `__new__` is incorrect: Expected `str | Buffer | SupportsInt | SupportsIndex | SupportsTrunc`, found `Unknown | Literal[0] | None | list[Unknown | int | None]`
- setuptools/_distutils/text_file.py:232:44: error[unsupported-operator] Operator `+` is not supported between objects of type `@Todo | int | None | Divergent` and `Literal[1]`
+ setuptools/_distutils/text_file.py:232:44: error[unsupported-operator] Operator `+` is not supported between objects of type `@Todo | int | None` and `Literal[1]`
- setuptools/_distutils/text_file.py:242:41: error[unsupported-operator] Operator `+` is not supported between objects of type `@Todo | int | None | Divergent` and `Literal[1]`
+ setuptools/_distutils/text_file.py:242:41: error[unsupported-operator] Operator `+` is not supported between objects of type `@Todo | int | None` and `Literal[1]`
- setuptools/_vendor/autocommand/autoparse.py:306:5: error[invalid-assignment] Object of type `Unknown & ~None` is not assignable to attribute `func` on type `_Wrapped[(...), Unknown, (argv=None), Unknown] | _Wrapped[(...), Unknown, Divergent, Unknown]`
- setuptools/_vendor/autocommand/autoparse.py:307:5: error[invalid-assignment] Object of type `Unknown` is not assignable to attribute `parser` on type `_Wrapped[(...), Unknown, (argv=None), Unknown] | _Wrapped[(...), Unknown, Divergent, Unknown]`
+ setuptools/_vendor/autocommand/autoparse.py:306:5: error[unresolved-attribute] Unresolved attribute `func` on type `_Wrapped[(...), Unknown, (argv=None), Unknown]`.
+ setuptools/_vendor/autocommand/autoparse.py:307:5: error[unresolved-attribute] Unresolved attribute `parser` on type `_Wrapped[(...), Unknown, (argv=None), Unknown]`.

prefect (https://github.com/PrefectHQ/prefect)
- src/integrations/prefect-aws/tests/test_s3.py:442:21: error[no-matching-overload] No overload matches arguments
- src/integrations/prefect-aws/tests/test_s3.py:449:21: error[no-matching-overload] No overload matches arguments
- src/integrations/prefect-docker/tests/test-project/flow.py:31:9: error[no-matching-overload] No overload matches arguments
- Found 5533 diagnostics
+ Found 5530 diagnostics

scikit-build-core (https://github.com/scikit-build/scikit-build-core)
- src/scikit_build_core/build/wheel.py:98:20: error[no-matching-overload] No overload of bound method `__init__` matches arguments
- Found 42 diagnostics
+ Found 41 diagnostics

pandas-stubs (https://github.com/pandas-dev/pandas-stubs)
+ pandas-stubs/_typing.pyi:1217:16: warning[unused-ignore-comment] Unused blanket `type: ignore` directive
- Found 5118 diagnostics
+ Found 5119 diagnostics

scipy (https://github.com/scipy/scipy)
- scipy/stats/_axis_nan_policy.py:713:9: error[invalid-assignment] Object of type `Signature` is not assignable to attribute `__signature__` on type `_Wrapped[(...), Unknown, (*args, *, _no_deco=Literal[False], **kwds), Unknown] | _Wrapped[(...), Unknown, Divergent, Unknown]`
+ scipy/stats/_axis_nan_policy.py:713:9: error[unresolved-attribute] Unresolved attribute `__signature__` on type `_Wrapped[(...), Unknown, (*args, *, _no_deco=Literal[False], **kwds), Unknown]`.

Memory usage changes were detected when running on open source projects
trio (https://github.com/python-trio/trio)
-     struct metadata = ~11MB
+     struct metadata = ~10MB

@astral-sh-bot
Copy link

astral-sh-bot bot commented Dec 11, 2025

ecosystem-analyzer results

Lint rule Added Removed Changed
invalid-assignment 0 3 0
unresolved-attribute 3 0 0
invalid-argument-type 0 0 2
invalid-return-type 0 0 2
unsupported-operator 0 0 2
possibly-missing-attribute 0 0 1
unused-ignore-comment 1 0 0
Total 4 3 7

Full report with detailed diff (timing results)

@codspeed-hq
Copy link

codspeed-hq bot commented Dec 11, 2025

CodSpeed Performance Report

Merging #21910 will not alter performance

Comparing cjm/nodiv (060a617) with main (3f63ea4)

Summary

✅ 22 untouched
⏩ 30 skipped1

Footnotes

  1. 30 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.

@carljm
Copy link
Contributor Author

carljm commented Dec 11, 2025

With #21906, this no longer has any impact on our mdtests. Pushing a rebase to see if it has any ecosystem impact worth pursuing.

@carljm
Copy link
Contributor Author

carljm commented Dec 11, 2025

Ok, this doesn't seem to hurt performance and there are cases in the ecosystem where it helps, so I think it's worth going ahead with. I'll add at least one example from the ecosystem as an mdtest and then put it up for review.

@carljm carljm marked this pull request as ready for review December 12, 2025 00:55
false,
)
};
if has_divergent_type_in_cycle(previous) && !has_divergent_type_in_cycle(self) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I remove the !has_divergent_type_in_cycle(self) requirement, we do get an oscillation in mdtest/regression/1377_iteration_count_mismatch.md. So it is possible to oscillate between types containing a Divergent from the current cycle. But it should not be possible to reintroduce a Divergent from the current cycle once it has been eliminated.

@carljm
Copy link
Contributor Author

carljm commented Dec 12, 2025

@mtshiba please take a look and let me know what you think.

@mtshiba
Copy link
Contributor

mtshiba commented Dec 12, 2025

Looks good!

@carljm carljm merged commit 0138cd2 into main Dec 12, 2025
43 checks passed
@carljm carljm deleted the cjm/nodiv branch December 12, 2025 03:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ecosystem-analyzer ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants