Skip to content

Add generic type inference to dmypy suggest - #22506

Open
yngbfyg wants to merge 6 commits into
python:masterfrom
yngbfyg:generic-suggestions
Open

yngbfyg wants to merge 6 commits into
python:masterfrom
yngbfyg:generic-suggestions

Conversation

@yngbfyg

@yngbfyg yngbfyg commented Nov 17, 2026

Copy link
Copy Markdown

Summary

Extend dmypy suggest to infer generic function signatures from function bodies and observed call sites.

Implemented features

  • Generic inference for identity functions: (T) -> T
  • Support for lists, tuples, and dictionaries
  • Generic callback inference using Callable[[T], R]
  • AST-based detection of argument and return-type relationships
  • Candidate validation through the existing SuggestionEngine
  • Protection against introducing new type-checking errors
  • Configurable --generic-min-calls option (our additional extension)

Testing

  • 44 unit and integration tests passed
  • 56 dmypy suggest tests passed
  • 8,369 type-checker tests passed
  • 13,276 fast regression tests passed
  • Mypy self-check and Ruff checks passed

Documentation

See LAB_II.md for the implementation details, usage instructions, supported patterns, limitations, and testing commands.

A runnable example is provided in demo_generic.py.

@github-actions

Copy link
Copy Markdown
Contributor

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants