stubgen failed to find function signature from native modules
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Feature
I have written a native module with a hand-written docstring and signature.
The signature is available via
import inspect
import mymod
inspect.signature(mymod.MyClass.method1)
# or
help(mymod.MyClass)
# correctly prints (a,b,c)
However stubgen -p mymod generates .pyi with
class Myclass:
@classmethod
def __init__(cls, *args, **kwargs) -> None: ...
def method1(self, *args, **kwargs) -> Any: ...
filled with *args and **kwargs instead of correct signatures. (Worse, method1 is in fact staticmethod so vscode complains with this stub)
The binding is written with rust pyo3.
Since all inspect.signature, help, and IPython can read the signature, I think the problem is in stubgen.
I don't know the internals of stubgen, but would it help to use inspect.signature when other methods in generate_stub_for_c_module fail?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading stubgen's generate_stub_for_c_module path and compare its current signature-discovery fallbacks with inspect.signature on the native module example. Done means stubgen emits the documented parameter signatures and preserves method kinds such as staticmethod instead of using generic *args and **kwargs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100