Skip to content

Conversation

konn
Copy link
Collaborator

@konn konn commented Jul 22, 2025

What have been done in this PR?

  • Supports @overload decorator for functions and methods.
  • With this PR, now pyo3_stub_gen automatically adds @overloaded decorator when there are multiple PyFunctionInfo or MethodInfo for the same function/method (current main just picks the last submitted one).
    • If there is only one entry, it don't emit @overload.
    • It also adds import typing if needed.
  • Fixes Function overloading #196.

@konn konn force-pushed the konn/overload-signatures branch from 5a1e0ac to d705595 Compare July 22, 2025 03:03
@konn konn force-pushed the konn/overload-signatures branch from 2b9a1b6 to 9408785 Compare July 22, 2025 03:18
@konn konn force-pushed the konn/overload-signatures branch from ba63325 to 68e80ba Compare July 23, 2025 01:34
@konn konn marked this pull request as ready for review July 23, 2025 01:35
@konn konn requested review from Copilot and termoshtt July 23, 2025 01:35
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for generating @overload decorators in Python stub files when multiple function or method signatures exist for the same name. The implementation automatically detects when there are multiple entries for the same function/method and generates appropriate @typing.overload decorators, while also ensuring the typing module is imported when needed.

  • Converts single function/method storage to collections that support multiple signatures per name
  • Adds automatic detection and generation of @typing.overload decorators
  • Implements conditional import of the typing module when overloads are present

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
pyo3-stub-gen/src/generate/variant_methods.rs Updates return type to use IndexMap for grouping methods by name
pyo3-stub-gen/src/generate/stub_info.rs Adds overload tracking and converts function/method storage to support multiple signatures
pyo3-stub-gen/src/generate/module.rs Implements overload decorator generation and conditional typing import
pyo3-stub-gen/src/generate/class.rs Updates class method handling to support overloaded methods
examples/pure/tests/test_python.py Adds test cases for overloaded functions and methods
examples/pure/src/lib.rs Adds example implementations demonstrating overload functionality
examples/pure/pure.pyi Shows generated stub file with overload decorators

Copy link
Member

@termoshtt termoshtt left a comment

Choose a reason for hiding this comment

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

LGTM

@termoshtt termoshtt enabled auto-merge (squash) July 23, 2025 06:38
@termoshtt termoshtt merged commit 08dc078 into main Jul 23, 2025
26 checks passed
@termoshtt termoshtt deleted the konn/overload-signatures branch July 23, 2025 06:39
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.

Function overloading
2 participants