From 96221e13df80c3ed78fdd0e3134f87843bcc0b18 Mon Sep 17 00:00:00 2001 From: Stefan Rickli Date: Sun, 29 Dec 2024 05:42:47 +0100 Subject: [PATCH] BUG: collections.abc.Callable does not allow tuple in Python 3.10 (#454) * BUG: crash: collections.abc.Callable does not allow tuple in Python 3.10 * REF: Document Python3.10-specific workaround * REF: Make flake8 happy --- pdoc/__init__.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pdoc/__init__.py b/pdoc/__init__.py index bb21faf4..00170d78 100644 --- a/pdoc/__init__.py +++ b/pdoc/__init__.py @@ -1354,8 +1354,12 @@ def maybe_replace_reprs(a): try: a = a.__origin__[args] except TypeError: + # XXX: Python 3.10-only: Convert to list since _CallableGenericAlias.__new__ + # currently cannot have tuples as arguments. + args_in = list(args[:-1]) + arg_out = args[-1] # collections.abc.Callable takes "([in], out)" - a = a.__origin__[(args[:-1], args[-1])] + a = a.__origin__[(args_in, arg_out)] # Recurse into lists if isinstance(a, (list, tuple)): return type(a)(map(maybe_replace_reprs, a))