Skip to content

[ty] Filter out unsatisfiable inference attempts during generic call narrowing#24025

Merged
ibraheemdev merged 3 commits intomainfrom
ibraheem/narrow-callable-short-circuit
Mar 17, 2026
Merged

[ty] Filter out unsatisfiable inference attempts during generic call narrowing#24025
ibraheemdev merged 3 commits intomainfrom
ibraheem/narrow-callable-short-circuit

Conversation

@ibraheemdev
Copy link
Member

@ibraheemdev ibraheemdev commented Mar 17, 2026

#23848 (comment) got me thinking about how to short-circuit earlier during generic call inference.

@ibraheemdev ibraheemdev added performance Potential performance improvement ty Multi-file analysis & type inference labels Mar 17, 2026
@astral-sh-bot
Copy link

astral-sh-bot bot commented Mar 17, 2026

Typing conformance results

No changes detected ✅

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

@astral-sh-bot
Copy link

astral-sh-bot bot commented Mar 17, 2026

Memory usage report

Summary

Project Old New Diff Outcome
flake8 48.15MB 48.15MB +0.01% (3.37kB)
trio 116.27MB 116.27MB -0.00% (1.62kB) ⬇️
sphinx 263.36MB 263.34MB -0.01% (19.79kB) ⬇️
prefect 701.12MB 701.10MB -0.00% (20.90kB) ⬇️

Significant changes

Click to expand detailed breakdown

flake8

Name Old New Diff Outcome
FunctionType 435.70kB 436.34kB +0.15% (656.00B)
Type<'db>::class_member_with_policy_ 567.30kB 567.81kB +0.09% (520.00B)
Type<'db>::try_call_dunder_get_ 374.37kB 374.88kB +0.14% (520.00B)
Type<'db>::class_member_with_policy_::interned_arguments 305.60kB 306.01kB +0.13% (416.00B)
FunctionType<'db>::signature_ 358.50kB 358.84kB +0.09% (344.00B)
CallableType 143.16kB 143.44kB +0.20% (288.00B)
Type<'db>::member_lookup_with_policy_ 485.98kB 486.12kB +0.03% (136.00B)
Type<'db>::member_lookup_with_policy_::interned_arguments 227.80kB 227.91kB +0.04% (104.00B)
Type<'db>::apply_specialization_ 217.04kB 217.14kB +0.05% (104.00B)
Type<'db>::try_call_dunder_get_::interned_arguments 84.09kB 84.20kB +0.12% (104.00B)
BoundMethodType<'db>::into_callable_type_ 13.61kB 13.70kB +0.69% (96.00B)
Type<'db>::apply_specialization_::interned_arguments 203.44kB 203.52kB +0.04% (80.00B)
BoundMethodType 52.11kB 52.19kB +0.15% (80.00B)
infer_scope_types_impl 999.73kB 999.69kB -0.00% (36.00B)
infer_definition_types 1.95MB 1.95MB +0.00% (36.00B)

trio

Name Old New Diff Outcome
StaticClassLiteral<'db>::try_mro_ 860.70kB 859.24kB -0.17% (1.46kB) ⬇️
FunctionType 1.49MB 1.49MB +0.04% (656.00B) ⬇️
Specialization 473.48kB 472.94kB -0.12% (560.00B) ⬇️
Type<'db>::class_member_with_policy_ 2.00MB 2.00MB +0.02% (520.00B) ⬇️
Type<'db>::try_call_dunder_get_ 1.37MB 1.37MB +0.04% (520.00B) ⬇️
infer_expression_types_impl 6.08MB 6.08MB -0.01% (480.00B) ⬇️
infer_scope_types_impl 4.76MB 4.76MB -0.01% (468.00B) ⬇️
Type<'db>::class_member_with_policy_::interned_arguments 1.11MB 1.11MB +0.04% (416.00B) ⬇️
StaticClassLiteral<'db>::try_mro_::interned_arguments 200.11kB 199.76kB -0.18% (360.00B) ⬇️
GenericAlias 200.46kB 200.11kB -0.18% (360.00B) ⬇️
infer_expression_type_impl 1.52MB 1.52MB -0.02% (360.00B) ⬇️
FunctionType<'db>::signature_ 1.07MB 1.07MB +0.03% (344.00B) ⬇️
CallableType 490.28kB 490.56kB +0.06% (288.00B) ⬇️
Type<'db>::apply_specialization_::interned_arguments 643.20kB 642.97kB -0.04% (240.00B) ⬇️
infer_definition_types 7.52MB 7.52MB -0.00% (216.00B) ⬇️
... 8 more

sphinx

Name Old New Diff Outcome
StaticClassLiteral<'db>::try_mro_ 2.10MB 2.10MB -0.11% (2.46kB) ⬇️
Type<'db>::class_member_with_policy_ 7.63MB 7.63MB -0.03% (2.43kB) ⬇️
Type<'db>::apply_specialization_ 1.63MB 1.63MB -0.09% (1.54kB) ⬇️
CallableType 932.22kB 930.95kB -0.14% (1.27kB) ⬇️
Type<'db>::member_lookup_with_policy_ 6.51MB 6.51MB -0.02% (1.25kB) ⬇️
StaticClassLiteral<'db>::implicit_attribute_inner_ 2.40MB 2.40MB -0.04% (1.09kB) ⬇️
FunctionType 3.10MB 3.09MB -0.03% (1.08kB) ⬇️
Specialization 1.02MB 1.02MB -0.10% (1.00kB) ⬇️
Type<'db>::apply_specialization_::interned_arguments 1.44MB 1.44MB -0.06% (960.00B) ⬇️
StaticClassLiteral<'db>::implicit_attribute_inner_::interned_arguments 1.93MB 1.93MB -0.05% (960.00B) ⬇️
infer_scope_types_impl 15.54MB 15.54MB -0.00% (672.00B) ⬇️
FunctionType<'db>::signature_ 2.26MB 2.26MB -0.03% (600.00B) ⬇️
cached_protocol_interface 184.80kB 184.23kB -0.31% (588.00B) ⬇️
StaticClassLiteral<'db>::try_mro_::interned_arguments 484.10kB 483.61kB -0.10% (504.00B) ⬇️
GenericAlias 450.42kB 449.93kB -0.11% (504.00B) ⬇️
... 12 more

prefect

Name Old New Diff Outcome
infer_scope_types_impl 53.11MB 53.11MB -0.01% (4.55kB) ⬇️
Type<'db>::class_member_with_policy_ 17.62MB 17.62MB -0.02% (3.90kB) ⬇️
Type<'db>::member_lookup_with_policy_ 16.17MB 16.17MB -0.01% (2.43kB) ⬇️
StaticClassLiteral<'db>::implicit_attribute_inner_ 10.03MB 10.02MB -0.02% (1.97kB) ⬇️
StaticClassLiteral<'db>::implicit_attribute_inner_::interned_arguments 5.21MB 5.21MB -0.03% (1.69kB) ⬇️
infer_definition_types 90.22MB 90.22MB -0.00% (1.21kB) ⬇️
Specialization 2.52MB 2.52MB -0.05% (1.17kB) ⬇️
Type<'db>::apply_specialization_ 3.61MB 3.61MB -0.03% (1.16kB) ⬇️
Type<'db>::member_lookup_with_policy_::interned_arguments 5.69MB 5.69MB -0.02% (1.12kB) ⬇️
infer_expression_types_impl 55.83MB 55.83MB -0.00% (1.11kB) ⬇️
Type<'db>::apply_specialization_::interned_arguments 2.90MB 2.90MB -0.04% (1.09kB) ⬇️
code_generator_of_static_class 1.81MB 1.80MB -0.06% (1.09kB) ⬇️
Type<'db>::try_call_dunder_get_ 10.58MB 10.58MB +0.01% (1016.00B) ⬇️
Type<'db>::class_member_with_policy_::interned_arguments 9.45MB 9.45MB -0.01% (832.00B) ⬇️
FunctionType 8.53MB 8.53MB +0.01% (656.00B) ⬇️
... 13 more

@astral-sh-bot
Copy link

astral-sh-bot bot commented Mar 17, 2026

ecosystem-analyzer results

Lint rule Added Removed Changed
invalid-await 0 40 0
invalid-return-type 0 1 0
Total 0 41 0

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

Full report with detailed diff (timing results)

@codspeed-hq
Copy link

codspeed-hq bot commented Mar 17, 2026

Merging this PR will improve performance by 13.83%

⚡ 2 improved benchmarks
✅ 25 untouched benchmarks
⏩ 30 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
WallTime static_frame 26.5 s 23.3 s +13.83%
WallTime colour_science 77.7 s 71.4 s +8.85%

Comparing ibraheem/narrow-callable-short-circuit (8f0350b) with main (1616095)

Open in CodSpeed

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.

@ibraheemdev ibraheemdev marked this pull request as ready for review March 17, 2026 21:34
Copy link
Member

@dcreager dcreager left a comment

Choose a reason for hiding this comment

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

Nice!

@ibraheemdev ibraheemdev merged commit 744c996 into main Mar 17, 2026
49 checks passed
@ibraheemdev ibraheemdev deleted the ibraheem/narrow-callable-short-circuit branch March 17, 2026 21:49
carljm added a commit that referenced this pull request Mar 17, 2026
* main:
  [ty] Filter out unsatisfiable inference attempts during generic call narrowing (#24025)
  [ty] Avoid inferring intersection types for call arguments (#23933)
  [ty] Pin mypy_primer in `setup_primer_project.py` (#24020)
  [`pycodestyle`] Recognize `pyrefly:` as a pragma comment (`E501`) (#24019)
  Add company AI policy to contributing guide (#24021)
  [ty] Remove the mypy_primer CI workflow (#24016)
  Update prek dependencies (#23980)
  [ty] Smarter semantic token classification for attribute access on union type (#23841)
  [ty] ecosystem-analyzer: Inline diffs and panic messages (#24015)
  [ty] Improve `.toml` support in the ty playground (#23476)
  PEP 639 license information (#19661)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Potential performance improvement ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants