Skip to content

[ty] Support ParamSpecs in ConstraintSet - #28028

Open
dhruvmanila wants to merge 15 commits into
dhruv/refactor-constraint-boundsfrom
dhruv/paramspec-constraint-range
Open

[ty] Support ParamSpecs in ConstraintSet#28028
dhruvmanila wants to merge 15 commits into
dhruv/refactor-constraint-boundsfrom
dhruv/paramspec-constraint-range

Conversation

@dhruvmanila

@dhruvmanila dhruvmanila commented Aug 25, 2026

Copy link
Copy Markdown
Member

Summary

Part of astral-sh/ty#3555. Depends on #28094.

Support ParamSpecs in the internal ConstraintSet.range, lower_bound, upper_bound, and equality constructors. Share normalization for concrete and symbolic parameter-list bounds, preserving full signatures, overloads, and generic binders while erasing callable return types.

Use parameter-list bottom/top as the effective defaults for missing ParamSpec endpoints, while keeping absent and explicitly supplied bounds distinct in storage. Recognize unrestricted ParamSpec ranges without discarding supplied bounds as inference evidence. Allow bare ParamSpecs during argument inference for these four internal constructors.

Solution extraction and specialization inference remain out of scope.

Test Plan

  • Concrete, symbolic, aliased, gradual, and overloaded bounds across the constructors.
  • Parameter kinds, defaults, variadics, return erasure, and generic-binder preservation.
  • Missing-bound equivalence to explicit parameter-list extrema and preservation of absent versus supplied evidence.
  • Self-bound constraints and unrestricted ParamSpec ranges.
  • Invalid parameter-list bounds and ordinary TypeVar, ParamSpec-component, TypeVarTuple, and subsequent unrelated TypeForm controls.

@dhruvmanila dhruvmanila added the ty Multi-file analysis & type inference label Aug 25, 2026
@astral-sh-bot

astral-sh-bot Bot commented Aug 25, 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 25, 2026

Copy link
Copy Markdown

Memory usage report

Summary

Project Old New Diff Outcome
trio 96.88MB 96.88MB +0.01% (6.34kB)
sphinx 172.63MB 172.63MB +0.00% (1.09kB)
flake8 40.22MB 40.22MB +0.00% (360.00B)
prefect 477.34MB 477.33MB -0.00% (12.31kB) ⬇️

Significant changes

Click to expand detailed breakdown

trio

Name Old New Diff Outcome
Type<'db>::class_member_with_policy_inner_ 1.29MB 1.29MB +0.15% (2.02kB)
MemberLookupKey 1.14MB 1.14MB +0.15% (1.73kB)
infer_definition_types 4.73MB 4.73MB +0.02% (1.14kB)
member_lookup_with_policy_inner 1.25MB 1.25MB +0.07% (968.00B)
StaticClassLiteral<'db>::variance_of_owner_::interned_arguments 44.43kB 45.29kB +1.93% (880.00B)
CallableType 1.44MB 1.43MB -0.05% (680.00B) ⬇️
infer_expression_types_impl 6.43MB 6.43MB +0.01% (640.00B)
TypeVarSetInner 263.80kB 263.27kB -0.20% (552.00B) ⬇️
StaticClassLiteral<'db>::try_mro_specialized_ 856.01kB 856.42kB +0.05% (424.00B)
Type<'db>::cached_materialization_::interned_arguments 323.98kB 323.59kB -0.12% (400.00B) ⬇️
StaticClassLiteral<'db>::variance_of_owner_ 23.98kB 24.38kB +1.63% (400.00B)
Type<'db>::cached_materialization_ 234.34kB 234.02kB -0.14% (328.00B) ⬇️
TypePair 1.03MB 1.03MB +0.02% (192.00B)
function_known_decorators 368.90kB 369.09kB +0.05% (192.00B)
GenericContext 571.66kB 571.51kB -0.03% (156.00B) ⬇️
... 16 more

sphinx

Name Old New Diff Outcome
CallableType 1.67MB 1.67MB +0.04% (640.00B)
infer_definition_types 11.61MB 11.61MB +0.00% (216.00B)
Type<'db>::cached_materialization_::interned_arguments 385.94kB 386.02kB +0.02% (80.00B)
infer_expression_types_impl 12.01MB 12.01MB +0.00% (64.00B)
Type<'db>::cached_materialization_ 255.95kB 256.00kB +0.02% (48.00B)
infer_scope_types_impl 6.13MB 6.13MB +0.00% (32.00B)
function_known_decorators 821.91kB 821.92kB +0.00% (16.00B)
infer_statement_types_impl 529.63kB 529.65kB +0.00% (16.00B)

flake8

Name Old New Diff Outcome
CallableType 295.14kB 295.45kB +0.11% (320.00B)
infer_definition_types 1.12MB 1.12MB +0.00% (40.00B)

prefect

Name Old New Diff Outcome
CallableType 8.57MB 8.56MB -0.05% (4.54kB) ⬇️
Type<'db>::apply_specialization_inner_::interned_arguments 5.42MB 5.42MB -0.05% (2.50kB) ⬇️
StaticClassLiteral<'db>::variance_of_owner_::interned_arguments 90.75kB 92.98kB +2.46% (2.23kB)
when_constraint_set_assignable_to_owned_impl 3.62MB 3.62MB +0.06% (2.14kB)
Type<'db>::apply_specialization_inner_ 3.73MB 3.72MB -0.04% (1.65kB) ⬇️
TypeVarSetInner 1.12MB 1.12MB -0.13% (1.54kB) ⬇️
Specialization 5.01MB 5.01MB -0.03% (1.52kB) ⬇️
FunctionType 6.83MB 6.83MB -0.02% (1.41kB) ⬇️
StaticClassLiteral<'db>::try_mro_specialized_ 4.49MB 4.50MB +0.03% (1.32kB)
Type<'db>::cached_materialization_::interned_arguments 1.50MB 1.49MB -0.08% (1.17kB) ⬇️
GenericAlias<'db>::variance_of_owner_::interned_arguments 65.14kB 64.02kB -1.72% (1.12kB) ⬇️
StaticClassLiteral<'db>::variance_of_owner_ 247.28kB 248.28kB +0.40% (1.00kB)
TypePair 8.00MB 8.00MB +0.01% (960.00B)
GenericContext 2.18MB 2.17MB -0.04% (840.00B) ⬇️
check_file_impl 6.79MB 6.79MB -0.01% (815.00B) ⬇️
... 38 more

@astral-sh-bot

astral-sh-bot Bot commented Aug 25, 2026

Copy link
Copy Markdown

ecosystem-analyzer results

Lint rule Added Removed Changed
invalid-return-type 0 1 0
unsound-return-statement 1 0 0
Total 1 1 0

Raw diff:

prefect (https://github.com/PrefectHQ/prefect)
- src/prefect/task_runners.py:436:16 error[invalid-return-type] Return type does not match returned value: expected `PrefectConcurrentFuture[R@ThreadPoolTaskRunner]`, found `PrefectConcurrentFuture[_T@run]`
+ src/prefect/task_runners.py:436:16 warning[unsound-return-statement] Unsound return statement: `PrefectConcurrentFuture[Unknown]` is not a subtype of `PrefectConcurrentFuture[R@ThreadPoolTaskRunner]`

Full report with detailed diff (timing results)

@dhruvmanila dhruvmanila changed the title [ty] Support ParamSpecs in ConstraintSet.range [ty] Support ParamSpecs in ConstraintSet.range Aug 25, 2026
@dhruvmanila dhruvmanila changed the title [ty] Support ParamSpecs in ConstraintSet.range [ty] Support ParamSpecs in ConstraintSet Aug 25, 2026
@dhruvmanila
dhruvmanila force-pushed the dhruv/paramspec-constraint-range branch from d68f81c to adc2681 Compare August 27, 2026 09:05
@dhruvmanila
dhruvmanila changed the base branch from main to dhruv/refactor-constraint-bounds August 27, 2026 09:06
@codspeed-hq

codspeed-hq Bot commented Aug 27, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 126 untouched benchmarks
⏩ 84 skipped benchmarks1


Comparing dhruv/paramspec-constraint-range (a1a8ab9) with dhruv/refactor-constraint-bounds (10474fb)

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.

@dhruvmanila
dhruvmanila force-pushed the dhruv/paramspec-constraint-range branch from adc2681 to abb795c Compare August 27, 2026 15:39
Allow the three required arguments to be passed by keyword, matching the existing internal stub.
Accept bare ParamSpec subjects in the internal range constructor and normalize callable bounds to parameter-list values. Preserve full signatures and overloads while erasing returns, and keep ordinary bounds and type-form validation unchanged.

Cover concrete, aliased, gradual, and overloaded bounds, including invalid forms and a computed-receiver validation regression.
Permit bare ParamSpec endpoints only for a bare ParamSpec subject. Normalize unprefixed callable references to their bound ParamSpec while retaining callable-owned generic binders and Concatenate prefixes.

Cover mixed and symbolic ranges, callable equivalence, and generic-binder preservation.
Remove duplicate keyword-call variants while retaining positional lower- and upper-bound TypeVarTuple rejection coverage.
Revert the synthetic range signature change at review request. Keyword-call support and alignment with the stub are outside this ParamSpec change.
Supply parameter-list bottom/top for missing ParamSpec endpoints through Constraint's effective accessors. Keep absent stored bounds separate from inference evidence and preserve ordinary TypeVar behavior.
@dhruvmanila
dhruvmanila force-pushed the dhruv/paramspec-constraint-range branch from abb795c to a1a8ab9 Compare August 27, 2026 16:00
@dhruvmanila
dhruvmanila marked this pull request as ready for review August 27, 2026 16:04
@dhruvmanila
dhruvmanila requested a review from a team as a code owner August 27, 2026 16:04
@astral-sh-bot
astral-sh-bot Bot requested a review from carljm August 27, 2026 16:04
@dhruvmanila
dhruvmanila requested review from dcreager and removed request for carljm August 27, 2026 16:04
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.

1 participant