@@ -102,7 +102,17 @@ def __init__(
102
102
self .stub_object = stub_object
103
103
self .runtime_object = runtime_object
104
104
self .stub_desc = stub_desc or str (getattr (stub_object , "type" , stub_object ))
105
- self .runtime_desc = runtime_desc or _truncate (repr (runtime_object ), 100 )
105
+
106
+ if runtime_desc is None :
107
+ runtime_sig = safe_inspect_signature (runtime_object )
108
+ if runtime_sig is None :
109
+ self .runtime_desc = _truncate (repr (runtime_object ), 100 )
110
+ else :
111
+ runtime_is_async = inspect .iscoroutinefunction (runtime_object )
112
+ description = describe_runtime_callable (runtime_sig , is_async = runtime_is_async )
113
+ self .runtime_desc = _truncate (description , 100 )
114
+ else :
115
+ self .runtime_desc = runtime_desc
106
116
107
117
def is_missing_stub (self ) -> bool :
108
118
"""Whether or not the error is for something missing from the stub."""
@@ -1000,7 +1010,7 @@ def verify_funcitem(
1000
1010
if signature :
1001
1011
stub_sig = Signature .from_funcitem (stub )
1002
1012
runtime_sig = Signature .from_inspect_signature (signature )
1003
- runtime_sig_desc = f' { "async " if runtime_is_coroutine else "" } def { signature } '
1013
+ runtime_sig_desc = describe_runtime_callable ( signature , is_async = runtime_is_coroutine )
1004
1014
stub_desc = str (stub_sig )
1005
1015
else :
1006
1016
runtime_sig_desc , stub_desc = None , None
@@ -1482,6 +1492,10 @@ def safe_inspect_signature(runtime: Any) -> inspect.Signature | None:
1482
1492
return None
1483
1493
1484
1494
1495
+ def describe_runtime_callable (signature : inspect .Signature , * , is_async : bool ) -> str :
1496
+ return f'{ "async " if is_async else "" } def { signature } '
1497
+
1498
+
1485
1499
def is_subtype_helper (left : mypy .types .Type , right : mypy .types .Type ) -> bool :
1486
1500
"""Checks whether ``left`` is a subtype of ``right``."""
1487
1501
left = mypy .types .get_proper_type (left )
0 commit comments