Skip to content

Commit 53dce4e

Browse files
authored
Don't crash if inspect.signature() fails on a function during stubgen. (#1124)
Use a maximally permissive type instead.
1 parent 71bfc9c commit 53dce4e

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/stubgen.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,17 @@ def put_function(self, fn: Callable[..., Any], name: Optional[str] = None, paren
428428
overload = self.import_object("typing", "overload")
429429
self.write_ln(f"@{overload}")
430430

431-
sig_str = f"{name}{self.signature_str(signature(fno))}"
431+
try:
432+
sig = signature(fno)
433+
except ValueError:
434+
sig = None
435+
436+
if sig is not None:
437+
sig_str = f"{name}{self.signature_str(sig)}"
438+
else:
439+
# If inspect.signature fails, use a maximally permissive type.
440+
any_type = self.import_object("typing", "Any")
441+
sig_str = f"{name}(*args, **kwargs) -> {any_type}"
432442

433443
# Potentially copy docstring from the implementation function
434444
docstr = fno.__doc__

0 commit comments

Comments
 (0)