Skip to content

Fix infer callable annotations - #4516

Open
WilliamK112 wants to merge 2 commits into
facebook:mainfrom
WilliamK112:agent/infer-callable-annotations
Open

Fix infer callable annotations#4516
WilliamK112 wants to merge 2 commits into
facebook:mainfrom
WilliamK112:agent/infer-callable-annotations

Conversation

@WilliamK112

@WilliamK112 WilliamK112 commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Share the Python annotation renderer used by stub generation with infer.
  • Render top-level function, callable, bound-method, and overload types as valid typing.Callable annotations and add the required import.
  • Skip inferred annotations that would require Incomplete, including nested callable types, instead of emitting Pyrefly's internal callable syntax into Python source.
  • Add regression coverage for callable parameters, returns, bound methods, and nested callable types.

Fixes #4507

Test Plan

  • CARGO_INCREMENTAL=0 CARGO_PROFILE_TEST_DEBUG=0 CARGO_PROFILE_DEV_DEBUG=0 CARGO_BUILD_JOBS=2 cargo test -p pyrefly commands::infer::test::
  • CARGO_INCREMENTAL=0 CARGO_PROFILE_TEST_DEBUG=0 CARGO_PROFILE_DEV_DEBUG=0 CARGO_BUILD_JOBS=2 cargo test -p pyrefly stubgen::tests::
  • CARGO_INCREMENTAL=0 CARGO_PROFILE_DEV_DEBUG=0 CARGO_PROFILE_TEST_DEBUG=0 CARGO_BUILD_JOBS=2 python3 test.py --no-test --no-tensor-shapes --no-conformance --no-jsonschema
  • git diff --check

AI usage

I used an AI coding assistant to help inspect the existing stub-generation implementation, implement the shared renderer, and review edge cases. I manually reviewed the diff and ran all validation listed above.

Signed-off-by: WilliamK112 <164879897+WilliamK112@users.noreply.github.com>
Signed-off-by: WilliamK112 <164879897+WilliamK112@users.noreply.github.com>
@meta-codesync

meta-codesync Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

This pull request has been imported. If you are a Meta employee, you can view this in D115700626. (Because this pull request was imported automatically, there will not be any future comments.)

@github-actions

Copy link
Copy Markdown

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pyrefly infer emits illegal callable syntax

2 participants