@@ -55,6 +55,17 @@ def __repr__(self) -> str:
55
55
T = TypeVar ("T" )
56
56
MaybeMissing : typing_extensions .TypeAlias = Union [T , Missing ]
57
57
58
+
59
+ class Unrepresentable :
60
+ """Marker object for unrepresentable parameter defaults."""
61
+
62
+ def __repr__ (self ) -> str :
63
+ return "<unrepresentable>"
64
+
65
+
66
+ UNREPRESENTABLE : typing_extensions .Final = Unrepresentable ()
67
+
68
+
58
69
_formatter : typing_extensions .Final = FancyFormatter (sys .stdout , sys .stderr , False )
59
70
60
71
@@ -681,6 +692,7 @@ def _verify_arg_default_value(
681
692
if (
682
693
stub_default is not UNKNOWN
683
694
and stub_default is not ...
695
+ and runtime_arg .default is not UNREPRESENTABLE
684
696
and (
685
697
stub_default != runtime_arg .default
686
698
# We want the types to match exactly, e.g. in case the stub has
@@ -1483,7 +1495,27 @@ def is_read_only_property(runtime: object) -> bool:
1483
1495
1484
1496
def safe_inspect_signature (runtime : Any ) -> inspect .Signature | None :
1485
1497
try :
1486
- return inspect .signature (runtime )
1498
+ try :
1499
+ return inspect .signature (runtime )
1500
+ except ValueError :
1501
+ if (
1502
+ hasattr (runtime , "__text_signature__" )
1503
+ and "<unrepresentable>" in runtime .__text_signature__
1504
+ ):
1505
+ # Try to fix up the signature. Workaround for
1506
+ # https://github.com/python/cpython/issues/87233
1507
+ sig = runtime .__text_signature__ .replace ("<unrepresentable>" , "..." )
1508
+ sig = inspect ._signature_fromstr (inspect .Signature , runtime , sig ) # type: ignore[attr-defined]
1509
+ assert isinstance (sig , inspect .Signature )
1510
+ new_params = [
1511
+ parameter .replace (default = UNREPRESENTABLE )
1512
+ if parameter .default is ...
1513
+ else parameter
1514
+ for parameter in sig .parameters .values ()
1515
+ ]
1516
+ return sig .replace (parameters = new_params )
1517
+ else :
1518
+ raise
1487
1519
except Exception :
1488
1520
# inspect.signature throws ValueError all the time
1489
1521
# catch RuntimeError because of https://bugs.python.org/issue39504
0 commit comments