Skip to content

[ty] Preserve type variables in invariant materialization subtyping - #28072

Draft
sharkdp wants to merge 5 commits into
mainfrom
codex/invariant-typevar-materializations
Draft

[ty] Preserve type variables in invariant materialization subtyping#28072
sharkdp wants to merge 5 commits into
mainfrom
codex/invariant-typevar-materializations

Conversation

@sharkdp

@sharkdp sharkdp commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Fixes ty#4201.

ty could ignore an unresolved type variable (T) when comparing types such as list[T]. For example, it considered Top[list[Unknown]]—which includes lists of every element type—a subtype of list[T], even though T could be int.

This removes that shortcut, so union simplification and narrowing preserve all possible alternatives. Related overlap checks and callable-parameter (ParamSpec) comparisons are adjusted to work without it.

The extra check discussed in this review comment is now unnecessary and is removed.

Follow-up to Preserve invariant materialization constraints.

@sharkdp sharkdp added the ty Multi-file analysis & type inference label Aug 26, 2026
@sharkdp
sharkdp force-pushed the codex/invariant-typevar-materializations branch from e8d39af to 55aa8f4 Compare August 27, 2026 07:03
@astral-sh-bot

astral-sh-bot Bot commented Aug 27, 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 97.79%. The percentage of expected errors that received a diagnostic held steady at 94.33%. The number of fully passing files held steady at 112/136.

@astral-sh-bot

astral-sh-bot Bot commented Aug 27, 2026

Copy link
Copy Markdown

Memory usage report

Summary

Project Old New Diff Outcome
prefect 478.16MB 478.21MB +0.01% (56.28kB)
trio 96.99MB 97.00MB +0.02% (16.16kB)
sphinx 172.94MB 172.95MB +0.00% (1.50kB)
flake8 40.23MB 40.23MB -

Significant changes

Click to expand detailed breakdown

prefect

Name Old New Diff Outcome
infer_expression_types_impl 24.42MB 24.40MB -0.10% (24.85kB) ⬇️
Specialization 5.01MB 5.02MB +0.24% (12.48kB)
when_constraint_set_assignable_to_owned_impl 3.92MB 3.93MB +0.31% (12.39kB)
TypePair 8.06MB 8.07MB +0.12% (10.22kB)
TypeVarSetInner 1.12MB 1.13MB +0.79% (9.04kB)
Type<'db>::cached_materialization_::interned_arguments 1.50MB 1.50MB +0.47% (7.27kB)
StaticClassLiteral<'db>::try_mro_specialized_ 4.49MB 4.50MB +0.10% (4.66kB)
is_redundant_with_impl 3.44MB 3.45MB +0.12% (4.38kB)
infer_definition_types 37.04MB 37.04MB +0.01% (4.27kB)
Type<'db>::cached_materialization_ 1.14MB 1.14MB +0.34% (3.98kB)
BoundTypeVarInstance 1.61MB 1.61MB +0.22% (3.61kB)
union_from_two_elements 177.03kB 180.40kB +1.90% (3.37kB)
ClassType<'db>::nearest_disjoint_base_ 262.69kB 265.23kB +0.97% (2.55kB)
Type<'db>::apply_specialization_inner_ 3.73MB 3.72MB -0.06% (2.27kB) ⬇️
is_possibly_constraint_set_assignable 346.73kB 348.80kB +0.60% (2.07kB)
... 50 more

trio

Name Old New Diff Outcome
merged_specialization_inner 134.14kB 136.40kB +1.68% (2.26kB)
TypeVarSetInner 263.80kB 265.46kB +0.63% (1.66kB)
assignable_solutions_impl::interned_arguments 88.97kB 87.45kB -1.71% (1.52kB) ⬇️
Type<'db>::apply_specialization_inner_::interned_arguments 1.26MB 1.26MB +0.10% (1.33kB)
when_constraint_set_assignable_to_owned_impl 746.88kB 748.12kB +0.17% (1.25kB)
FunctionType 1.43MB 1.43MB +0.07% (1.05kB)
infer_expression_types_impl 6.42MB 6.42MB +0.02% (1.01kB)
Type<'db>::apply_specialization_inner_ 879.78kB 880.72kB +0.11% (960.00B)
Specialization 1.12MB 1.12MB +0.08% (896.00B)
assignable_solutions_impl 165.16kB 164.34kB -0.50% (840.00B) ⬇️
Type<'db>::class_member_with_policy_inner_ 1.29MB 1.29MB +0.06% (800.00B)
GenericContext 571.66kB 572.33kB +0.12% (684.00B)
TypePair 1.04MB 1.04MB +0.06% (672.00B)
infer_definition_types 4.72MB 4.72MB +0.01% (592.00B)
MemberLookupKey 1.14MB 1.14MB +0.04% (520.00B)
... 34 more

sphinx

Name Old New Diff Outcome
when_constraint_set_assignable_to_owned_impl 908.56kB 908.98kB +0.05% (424.00B)
TypePair 2.17MB 2.17MB +0.02% (384.00B)
infer_expression_types_impl 11.94MB 11.94MB +0.00% (312.00B)
infer_definition_types 11.58MB 11.58MB +0.00% (264.00B)
Type<'db>::apply_specialization_inner_::interned_arguments 1.83MB 1.83MB -0.01% (240.00B) ⬇️
is_redundant_with_impl 790.76kB 790.91kB +0.02% (160.00B)
TypeVarSetInner 452.88kB 453.02kB +0.03% (148.00B)
analyze_non_terminal_call 482.86kB 483.00kB +0.03% (144.00B)
Type<'db>::apply_specialization_inner_ 1.16MB 1.16MB -0.01% (144.00B) ⬇️
union_from_two_elements 76.42kB 76.56kB +0.18% (144.00B)
TypeVarInference 447.98kB 447.86kB -0.03% (120.00B) ⬇️
all_narrowing_constraints_for_expression 2.39MB 2.39MB +0.00% (96.00B)
loop_header_reachability 250.14kB 250.24kB +0.04% (96.00B)
GenericAlias 665.02kB 664.95kB -0.01% (72.00B) ⬇️
merged_specialization_inner 150.55kB 150.52kB -0.03% (40.00B) ⬇️
... 2 more

@astral-sh-bot

astral-sh-bot Bot commented Aug 27, 2026

Copy link
Copy Markdown

ecosystem-analyzer results

Lint rule Added Removed Changed
invalid-argument-type 18 0 12
invalid-return-type 8 0 6
invalid-assignment 4 0 9
invalid-yield 3 0 0
unsound-return-statement 2 1 0
no-matching-overload 1 1 0
type-assertion-failure 2 0 0
redundant-cast 0 1 0
unresolved-attribute 1 0 0
Total 39 3 27
Raw diff (69 changes)
anyio (https://github.com/agronholm/anyio)
+ src/anyio/itertools.py:116:13 error[invalid-assignment] Object of type `Top[_TeeState[Unknown]]` is not assignable to attribute `_state` of type `_TeeState[T@_TeeAsyncIterator]`
+ src/anyio/itertools.py:117:13 error[invalid-assignment] Object of type `Top[_TeeLink[Unknown]]` is not assignable to attribute `_link` of type `_TeeLink[T@_TeeAsyncIterator]`

archinstall (https://github.com/archlinux/archinstall)
- archinstall/tui/result.py:71:10 warning[redundant-cast] Value is already of type `list[ValueT@Result]`

cki-lib (https://gitlab.com/cki-project/cki-lib)
+ cki_lib/misc.py:68:24 error[invalid-yield] Yield type `object` does not match annotated yield type `T@flattened`

core (https://github.com/home-assistant/core)
+ homeassistant/components/datadog/__init__.py:85:31 error[invalid-argument-type] Argument to bound method `EventBus.async_listen` is incorrect: Expected `EventType[Mapping[str, Any]] | str`, found `EventType[EventStateChangedData]`
+ homeassistant/components/influxdb/__init__.py:595:35 error[invalid-argument-type] Argument to bound method `EventBus.async_listen` is incorrect: Expected `EventType[Mapping[str, Any]] | str`, found `EventType[EventStateChangedData]`
+ homeassistant/components/statsd/__init__.py:91:21 error[invalid-argument-type] Argument to bound method `EventBus.listen` is incorrect: Expected `EventType[Mapping[str, Any]] | str`, found `EventType[EventStateChangedData]`
- homeassistant/core.py:2482:17 error[invalid-argument-type] Argument to bound method `EventBus.async_fire_internal` is incorrect: Expected `EventType[EventStateReportedData | dict[str, str | datetime | State | None]] | str`, found `EventType[EventStateReportedData]`
+ homeassistant/core.py:2482:17 error[invalid-argument-type] Argument to bound method `EventBus.async_fire_internal` is incorrect: Expected `EventType[dict[str, str | datetime | State | None]] | str`, found `EventType[EventStateReportedData]`
+ homeassistant/helpers/device_registry.py:2941:13 error[invalid-argument-type] Argument to bound method `EventBus.async_fire_internal` is incorrect: Expected `EventType[_EventDeviceRegistryUpdatedData_Update] | str`, found `EventType[EventDeviceRegistryUpdatedData]`
+ homeassistant/helpers/device_registry.py:3432:43 error[invalid-argument-type] Argument to bound method `EventBus.async_fire_internal` is incorrect: Expected `EventType[_EventDeviceRegistryUpdatedData_Create | _EventDeviceRegistryUpdatedData_Update] | str`, found `EventType[EventDeviceRegistryUpdatedData]`
+ homeassistant/helpers/device_registry.py:3615:43 error[invalid-argument-type] Argument to bound method `EventBus.async_fire_internal` is incorrect: Expected `EventType[_EventDeviceRegistryUpdatedData_Create | _EventDeviceRegistryUpdatedData_Update] | str`, found `EventType[EventDeviceRegistryUpdatedData]`
+ homeassistant/helpers/device_registry.py:4104:13 error[invalid-argument-type] Argument to bound method `EventBus.async_fire_internal` is incorrect: Expected `EventType[_EventDeviceRegistryUpdatedData_Remove] | str`, found `EventType[EventDeviceRegistryUpdatedData]`
+ homeassistant/helpers/device_registry.py:4135:13 error[invalid-argument-type] Argument to bound method `EventBus.async_fire_internal` is incorrect: Expected `EventType[_EventDeviceRegistryUpdatedData_Remove] | str`, found `EventType[EventDeviceRegistryUpdatedData]`
+ homeassistant/helpers/entity_registry.py:1616:13 error[invalid-argument-type] Argument to bound method `EventBus.async_fire_internal` is incorrect: Expected `EventType[_EventEntityRegistryUpdatedData_CreateRemove] | str`, found `EventType[EventEntityRegistryUpdatedData]`
+ homeassistant/helpers/entity_registry.py:1664:13 error[invalid-argument-type] Argument to bound method `EventBus.async_fire_internal` is incorrect: Expected `EventType[_EventEntityRegistryUpdatedData_CreateRemove] | str`, found `EventType[EventEntityRegistryUpdatedData]`
+ homeassistant/helpers/entity_registry.py:2014:43 error[invalid-argument-type] Argument to bound method `EventBus.async_fire_internal` is incorrect: Expected `EventType[_EventEntityRegistryUpdatedData_Update] | str`, found `EventType[EventEntityRegistryUpdatedData]`
+ homeassistant/helpers/floor_registry.py:225:13 error[invalid-argument-type] Argument to bound method `EventBus.async_fire_internal` is incorrect: Expected `EventType[_EventFloorRegistryUpdatedData_Create_Remove_Update] | str`, found `EventType[EventFloorRegistryUpdatedData]`
+ homeassistant/helpers/floor_registry.py:238:13 error[invalid-argument-type] Argument to bound method `EventBus.async_fire_internal` is incorrect: Expected `EventType[_EventFloorRegistryUpdatedData_Create_Remove_Update] | str`, found `EventType[EventFloorRegistryUpdatedData]`
+ homeassistant/helpers/floor_registry.py:280:13 error[invalid-argument-type] Argument to bound method `EventBus.async_fire_internal` is incorrect: Expected `EventType[_EventFloorRegistryUpdatedData_Create_Remove_Update] | str`, found `EventType[EventFloorRegistryUpdatedData]`
+ homeassistant/helpers/floor_registry.py:307:13 error[invalid-argument-type] Argument to bound method `EventBus.async_fire_internal` is incorrect: Expected `EventType[_EventFloorRegistryUpdatedData_Reorder] | str`, found `EventType[EventFloorRegistryUpdatedData]`
- homeassistant/scripts/benchmark/__init__.py:143:29 error[invalid-argument-type] Argument to bound method `EventBus.async_fire` is incorrect: Expected `EventType[EventStateChangedData | dict[str, str | State]] | str`, found `EventType[EventStateChangedData]`
+ homeassistant/scripts/benchmark/__init__.py:143:29 error[invalid-argument-type] Argument to bound method `EventBus.async_fire` is incorrect: Expected `EventType[dict[str, str | State]] | str`, found `EventType[EventStateChangedData]`
- homeassistant/scripts/benchmark/__init__.py:176:29 error[invalid-argument-type] Argument to bound method `EventBus.async_fire` is incorrect: Expected `EventType[EventStateChangedData | dict[str, str | State]] | str`, found `EventType[EventStateChangedData]`
+ homeassistant/scripts/benchmark/__init__.py:176:29 error[invalid-argument-type] Argument to bound method `EventBus.async_fire` is incorrect: Expected `EventType[dict[str, str | State]] | str`, found `EventType[EventStateChangedData]`
- homeassistant/scripts/benchmark/__init__.py:214:29 error[invalid-argument-type] Argument to bound method `EventBus.async_fire` is incorrect: Expected `EventType[EventStateChangedData | dict[str, str | State]] | str`, found `EventType[EventStateChangedData]`
+ homeassistant/scripts/benchmark/__init__.py:214:29 error[invalid-argument-type] Argument to bound method `EventBus.async_fire` is incorrect: Expected `EventType[dict[str, str | State]] | str`, found `EventType[EventStateChangedData]`

discord.py (https://github.com/Rapptz/discord.py)
+ discord/ext/commands/cog.py:461:32 error[invalid-yield] Yield type `Top[Command[Unknown, (...), Any]]` does not match annotated yield type `Command[Self@walk_commands, (...), Any]`
+ discord/ext/commands/core.py:1455:28 error[invalid-yield] Yield type `Top[Command[Unknown, (...), Any]]` does not match annotated yield type `Command[CogT@GroupMixin, (...), Any]`
+ discord/ext/commands/core.py:1499:16 error[invalid-return-type] Return type does not match returned value: expected `Command[CogT@GroupMixin, (...), Any] | None`, found `Top[Command[Unknown, (...), Any]] | Unknown`

meson (https://github.com/mesonbuild/meson)
+ mesonbuild/modules/hotdoc.py:61:12 error[invalid-return-type] Return type does not match returned value: expected `list[_T@ensure_list]`, found `(_T@ensure_list & Top[list[Unknown]]) | list[_T@ensure_list]`
+ mesonbuild/utils/universal.py:1912:12 error[invalid-return-type] Return type does not match returned value: expected `list[_T@typeslistify]`, found `(_T@typeslistify & Top[list[Unknown]]) | Top[list[Unknown & _T@typeslistify]]`

mkdocs (https://github.com/mkdocs/mkdocs)
+ mkdocs/config/config_options.py:219:20 error[invalid-return-type] Return type does not match returned value: expected `list[T@ListOfItems]`, found `Top[list[Unknown]] & ~AlwaysTruthy`

optuna (https://github.com/optuna/optuna)
- optuna/storages/_rdb/alembic/versions/v1.3.0.a.py:63:59 error[invalid-argument-type] Argument to function `loads` is incorrect: Expected `str | bytes | bytearray`, found `Column[str]`
+ optuna/storages/_rdb/alembic/versions/v1.3.0.a.py:63:59 error[invalid-argument-type] Argument to function `loads` is incorrect: Expected `str | bytes | bytearray`, found `Column[Unknown]`
- optuna/storages/_rdb/alembic/versions/v3.0.0.a.py:158:13 error[invalid-assignment] Object of type `str` is not assignable to attribute `distribution_json` of type `Column[str]`
+ optuna/storages/_rdb/alembic/versions/v3.0.0.a.py:158:13 error[invalid-assignment] Object of type `str` is not assignable to attribute `distribution_json` of type `Column[Unknown]`
- optuna/storages/_rdb/alembic/versions/v3.0.0.a.py:159:17 error[invalid-argument-type] Argument to function `migrate_new_distribution` is incorrect: Expected `str`, found `Column[str]`
+ optuna/storages/_rdb/alembic/versions/v3.0.0.a.py:159:17 error[invalid-argument-type] Argument to function `migrate_new_distribution` is incorrect: Expected `str`, found `Column[Unknown]`
- optuna/storages/_rdb/alembic/versions/v3.0.0.a.py:187:13 error[invalid-assignment] Object of type `str` is not assignable to attribute `distribution_json` of type `Column[str]`
+ optuna/storages/_rdb/alembic/versions/v3.0.0.a.py:187:13 error[invalid-assignment] Object of type `str` is not assignable to attribute `distribution_json` of type `Column[Unknown]`
- optuna/storages/_rdb/alembic/versions/v3.0.0.a.py:188:17 error[invalid-argument-type] Argument to function `restore_old_distribution` is incorrect: Expected `str`, found `Column[str]`
+ optuna/storages/_rdb/alembic/versions/v3.0.0.a.py:188:17 error[invalid-argument-type] Argument to function `restore_old_distribution` is incorrect: Expected `str`, found `Column[Unknown]`
- optuna/storages/_rdb/alembic/versions/v3.0.0.c.py:128:25 error[invalid-assignment] Object of type `Column[float]` is not assignable to `float`
+ optuna/storages/_rdb/alembic/versions/v3.0.0.c.py:128:25 error[invalid-assignment] Object of type `Column[Unknown]` is not assignable to `float`
- optuna/storages/_rdb/alembic/versions/v3.0.0.d.py:132:25 error[invalid-assignment] Object of type `Column[float]` is not assignable to `float`
+ optuna/storages/_rdb/alembic/versions/v3.0.0.d.py:132:25 error[invalid-assignment] Object of type `Column[Unknown]` is not assignable to `float`
- optuna/storages/_rdb/storage.py:342:17 error[invalid-assignment] Invalid assignment to data descriptor attribute `value_json` on type `StudyUserAttributeModel`: Argument type `MappedColumn[Any] | Column[str]` does not satisfy upper bound `Mapped[Any]` of type variable `Self`
+ optuna/storages/_rdb/storage.py:342:17 error[invalid-assignment] Invalid assignment to data descriptor attribute `value_json` on type `StudyUserAttributeModel`: Argument type `MappedColumn[Any] | Column[Unknown]` does not satisfy upper bound `Mapped[Any]` of type variable `Self`
- optuna/storages/_rdb/storage.py:354:17 error[invalid-assignment] Invalid assignment to data descriptor attribute `value_json` on type `StudySystemAttributeModel`: Argument type `MappedColumn[Any] | Column[str]` does not satisfy upper bound `Mapped[Any]` of type variable `Self`
+ optuna/storages/_rdb/storage.py:354:17 error[invalid-assignment] Invalid assignment to data descriptor attribute `value_json` on type `StudySystemAttributeModel`: Argument type `MappedColumn[Any] | Column[Unknown]` does not satisfy upper bound `Mapped[Any]` of type variable `Self`
- optuna/storages/_rdb/storage.py:368:16 error[invalid-return-type] Return type does not match returned value: expected `str`, found `Any | Column[str]`
+ optuna/storages/_rdb/storage.py:368:16 error[invalid-return-type] Return type does not match returned value: expected `str`, found `Any | Column[Unknown]`
- optuna/storages/_rdb/storage.py:382:48 error[invalid-argument-type] Argument to function `loads` is incorrect: Expected `str | bytes | bytearray`, found `Any | Column[str]`
+ optuna/storages/_rdb/storage.py:382:48 error[invalid-argument-type] Argument to function `loads` is incorrect: Expected `str | bytes | bytearray`, found `Any | Column[Unknown]`
- optuna/storages/_rdb/storage.py:384:16 error[invalid-return-type] Return type does not match returned value: expected `dict[str, Any]`, found `dict[Any | Column[str], Any]`
+ optuna/storages/_rdb/storage.py:384:16 error[invalid-return-type] Return type does not match returned value: expected `dict[str, Any]`, found `dict[Any | Column[Unknown], Any]`
- optuna/storages/_rdb/storage.py:391:50 error[invalid-argument-type] Argument to function `loads` is incorrect: Expected `str | bytes | bytearray`, found `Any | Column[str]`
+ optuna/storages/_rdb/storage.py:391:50 error[invalid-argument-type] Argument to function `loads` is incorrect: Expected `str | bytes | bytearray`, found `Any | Column[Unknown]`
- optuna/storages/_rdb/storage.py:393:16 error[invalid-return-type] Return type does not match returned value: expected `dict[str, Any]`, found `dict[Any | Column[str], Any]`
+ optuna/storages/_rdb/storage.py:393:16 error[invalid-return-type] Return type does not match returned value: expected `dict[str, Any]`, found `dict[Any | Column[Unknown], Any]`
- optuna/storages/_rdb/storage.py:401:48 error[invalid-argument-type] Argument to function `loads` is incorrect: Expected `str | bytes | bytearray`, found `Any | Column[str]`
+ optuna/storages/_rdb/storage.py:401:48 error[invalid-argument-type] Argument to function `loads` is incorrect: Expected `str | bytes | bytearray`, found `Any | Column[Unknown]`
- optuna/storages/_rdb/storage.py:403:16 error[invalid-return-type] Return type does not match returned value: expected `dict[str, Any]`, found `dict[Any | Column[str], Any]`
+ optuna/storages/_rdb/storage.py:403:16 error[invalid-return-type] Return type does not match returned value: expected `dict[str, Any]`, found `dict[Any | Column[Unknown], Any]`
- optuna/storages/_rdb/storage.py:411:50 error[invalid-argument-type] Argument to function `loads` is incorrect: Expected `str | bytes | bytearray`, found `Any | Column[str]`
+ optuna/storages/_rdb/storage.py:411:50 error[invalid-argument-type] Argument to function `loads` is incorrect: Expected `str | bytes | bytearray`, found `Any | Column[Unknown]`
- optuna/storages/_rdb/storage.py:413:16 error[invalid-return-type] Return type does not match returned value: expected `dict[str, Any]`, found `dict[Any | Column[str], Any]`
+ optuna/storages/_rdb/storage.py:413:16 error[invalid-return-type] Return type does not match returned value: expected `dict[str, Any]`, found `dict[Any | Column[Unknown], Any]`
- optuna/storages/_rdb/storage.py:645:21 error[invalid-argument-type] Argument to function `json_to_distribution` is incorrect: Expected `str`, found `Any | Column[str]`
+ optuna/storages/_rdb/storage.py:645:21 error[invalid-argument-type] Argument to function `json_to_distribution` is incorrect: Expected `str`, found `Any | Column[Unknown]`
- optuna/storages/_rdb/storage.py:668:16 error[invalid-return-type] Return type does not match returned value: expected `float`, found `Any | Column[float]`
+ optuna/storages/_rdb/storage.py:668:16 error[invalid-return-type] Return type does not match returned value: expected `float`, found `Any | Column[Unknown]`
- optuna/storages/_rdb/storage.py:716:13 error[invalid-assignment] Invalid assignment to data descriptor attribute `value` on type `TrialValueModel`: Argument type `MappedColumn[Any] | Column[float]` does not satisfy upper bound `Mapped[Any]` of type variable `Self`
+ optuna/storages/_rdb/storage.py:716:13 error[invalid-assignment] Invalid assignment to data descriptor attribute `value` on type `TrialValueModel`: Argument type `MappedColumn[Any] | Column[Unknown]` does not satisfy upper bound `Mapped[Any]` of type variable `Self`
- optuna/storages/_rdb/storage.py:755:13 error[invalid-assignment] Invalid assignment to data descriptor attribute `intermediate_value` on type `TrialIntermediateValueModel`: Argument type `MappedColumn[Any] | Column[float]` does not satisfy upper bound `Mapped[Any]` of type variable `Self`
+ optuna/storages/_rdb/storage.py:755:13 error[invalid-assignment] Invalid assignment to data descriptor attribute `intermediate_value` on type `TrialIntermediateValueModel`: Argument type `MappedColumn[Any] | Column[Unknown]` does not satisfy upper bound `Mapped[Any]` of type variable `Self`
- optuna/storages/_rdb/storage.py:1211:13 error[invalid-assignment] Invalid assignment to data descriptor attribute `library_version` on type `VersionInfoModel`: Argument type `MappedColumn[Any] | Column[str]` does not satisfy upper bound `Mapped[Any]` of type variable `Self`
+ optuna/storages/_rdb/storage.py:1211:13 error[invalid-assignment] Invalid assignment to data descriptor attribute `library_version` on type `VersionInfoModel`: Argument type `MappedColumn[Any] | Column[Unknown]` does not satisfy upper bound `Mapped[Any]` of type variable `Self`

pandas-stubs (https://github.com/pandas-dev/pandas-stubs)
+ tests/test_pandas.py:525:11 error[type-assertion-failure] Type `ndarray[tuple[int], dtype[numpy.bool[builtins.bool]]]` does not match asserted type `ndarray[tuple[Any, ...], dtype[numpy.bool[builtins.bool]]]`
+ tests/test_pandas.py:526:11 error[type-assertion-failure] Type `ndarray[tuple[int], dtype[numpy.bool[builtins.bool]]]` does not match asserted type `ndarray[tuple[Any, ...], dtype[numpy.bool[builtins.bool]]]`

prefect (https://github.com/PrefectHQ/prefect)
- src/integrations/prefect-redis/tests/test_tasks.py:52:12 warning[unsound-return-statement] Unsound return statement: `Unknown` is not a subtype of `str`
+ src/prefect/_internal/states.py:239:16 error[invalid-return-type] Return type does not match returned value: expected `State[R@return_value_to_state_sync]`, found `R@return_value_to_state_sync & Top[State[Unknown]]`
+ src/prefect/futures.py:252:13 error[invalid-assignment] Object of type `R@PrefectConcurrentFuture & Top[State[Unknown]]` is not assignable to attribute `_final_state` of type `State[R@PrefectConcurrentFuture] | None`
+ src/prefect/futures.py:270:17 error[invalid-assignment] Object of type `R@PrefectConcurrentFuture & Top[State[Unknown]]` is not assignable to attribute `_final_state` of type `State[R@PrefectConcurrentFuture] | None`
- src/prefect/futures.py:277:19 error[no-matching-overload] No overload of bound method `State.result` matches arguments
+ src/prefect/futures.py:277:19 error[unresolved-attribute] Attribute `result` is not defined on `None` in union `State[R@PrefectConcurrentFuture] | None`
+ src/prefect/input/run_input.py:890:16 error[invalid-return-type] Return type does not match returned value: expected `GetAutomaticInputHandler[T@receive_input] | GetInputHandler[R@receive_input]`, found `Top[GetAutomaticInputHandler[Unknown]]`
+ src/prefect/server/database/query_components.py:577:13 warning[unsound-return-statement] Unsound return statement: `Select[tuple[Unknown, datetime]]` is not a subtype of `Select[tuple[datetime, datetime]]`
+ src/prefect/states.py:369:16 error[invalid-return-type] Return type does not match returned value: expected `State[R@return_value_to_state]`, found `R@return_value_to_state & Top[State[Unknown]]`
+ src/prefect/task_engine.py:628:34 error[invalid-argument-type] Argument to bound method `SyncTaskRunEngine.handle_retry` is incorrect: Expected `Exception | State[R@SyncTaskRunEngine]`, found `R@SyncTaskRunEngine & Top[State[Unknown]]`
+ src/prefect/task_engine.py:1253:40 error[invalid-argument-type] Argument to bound method `AsyncTaskRunEngine.handle_retry` is incorrect: Expected `Exception | State[R@AsyncTaskRunEngine]`, found `R@AsyncTaskRunEngine & Top[State[Unknown]]`

scrapy (https://github.com/scrapy/scrapy)
+ scrapy/utils/defer.py:392:16 error[invalid-return-type] Return type does not match returned value: expected `Deferred[_T@deferred_from_coro] | _T2@deferred_from_coro`, found `(Awaitable[_T@deferred_from_coro] & Top[Deferred[Unknown]]) | (_T2@deferred_from_coro & Top[Deferred[Unknown]])`
+ scrapy/utils/defer.py:571:41 error[invalid-argument-type] Argument to function `maybe_deferred_to_future` is incorrect: Expected `Deferred[_T@ensure_awaitable]`, found `(_T@ensure_awaitable & Top[Deferred[Unknown]]) | (Awaitable[_T@ensure_awaitable] & Top[Deferred[Unknown]])`

streamlit (https://github.com/streamlit/streamlit)
+ lib/streamlit/runtime/caching/cache_data_api.py:831:20 warning[unsound-return-statement] Unsound return statement: `Any & Top[CachedResult[Unknown]]` is not a subtype of `CachedResult[R@DataCache]`

tornado (https://github.com/tornadoweb/tornado)
+ tornado/concurrent.py:170:9 error[no-matching-overload] No overload of function `future_add_done_callback` matches arguments

Full report with detailed diff (timing results)

@codspeed-hq

codspeed-hq Bot commented Aug 27, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 23.38%

⚠️ 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 regressed benchmark
✅ 125 untouched benchmarks
⏩ 84 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation ty_micro[invariant_generic_return_union] 198.5 ms 259.1 ms -23.38%

Tip

Investigate this regression with the CodSpeed MCP and your agent.


Comparing codex/invariant-typevar-materializations (a48e5bd) with main (1776127)

Open in CodSpeed

Footnotes

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

Validate possible overlap against TypeVar bounds and constraints, while retaining incompatible union alternatives so inference can still report argument errors. Add coverage for bounded and constrained nested type variables.

Compare fixed ParamSpecs directly with materialization endpoints and clarify the parameter kind distinction between top and bottom.
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.

Top[list[Unknown]] incorrectly considered a subtype of list[T]

1 participant