Reproduce an annotated function declaration

Hi,
I need to auto-create stub modules for a large embedded Python module (can’t load the thing into mypy …). So I’m looking for something that takes a function/module and returns the text I need to declare it. As in:

def fn(a:int,/,b:str,*,c:float|None=None) -> bool:
    ...
assert make_stub(fn).remove(" ") == "fn(a:int,/,b:str,*,c:float|None=None)->bool"

Does something like this exist? If not, fine, I know how to write it – but re-inventing the wheel is not on top of my list of priorities.

inspect.signature probably?

>>> def fn(a: int, /, b: str, *, c: float | None = None) -> bool: pass
>>> inspect.signature(fn)
<Signature (a: int, /, b: str, *, c: float | None = None) -> bool>

>>> def make_stub(f):
...     name = f.__name__
...     sig = inspect.signature(f)
...     return f"def {name}{sig}: ..."
...
>>> make_stub(fn)
'def fn(a: int, /, b: str, *, c: float | None = None) -> bool: ...'

You may also want to use mypy’s stubgen tool.