11"""
22Implementation of sphinx module.
33"""
4+ import collections .abc
45import importlib
56import logging
67from inspect import getattr_static
1718 get_type_hints ,
1819)
1920
21+ # todo: switch from typing_inspect over to typing once typing implements it completely
2022import typing_inspect
2123
2224from ...api import AllTracker , get_generic_bases , inheritdoc
@@ -250,7 +252,7 @@ def _resolve_attribute_signatures(self, cls: Type) -> None:
250252
251253 def _substitute_type_vars_in_type_expression (
252254 type_expression : Union [Type , TypeVar ]
253- ) -> Union [type , TypeVar ]:
255+ ) -> Union [Type , TypeVar ]:
254256 # recursively substitute type vars with their resolutions
255257 if isinstance (type_expression , TypeVar ):
256258 # resolve type variables defined by Generic[] in the
@@ -260,6 +262,14 @@ def _substitute_type_vars_in_type_expression(
260262 # dynamically resolve type variables inside nested type expressions
261263 args = typing_inspect .get_args (type_expression )
262264 if args :
265+ # unpack callable args, since copy_with() expects a flat tuple
266+ # (arg_1, arg_2, ..., arg_n, return)
267+ # instead of ([arg_1, arg_2, ..., arg_n], return)
268+ if typing_inspect .get_origin (
269+ type_expression
270+ ) is collections .abc .Callable and isinstance (args [0 ], list ):
271+ args = (* args [0 ], * args [1 :])
272+
263273 # noinspection PyUnresolvedReferences
264274 return type_expression .copy_with (
265275 tuple (map (_substitute_type_vars_in_type_expression , args ))
@@ -295,7 +305,7 @@ def _get_defining_class(method: FunctionType) -> Optional[type]:
295305 except NameError :
296306 # we could not find the container of the given method in the method's global
297307 # namespace - this is likely an inherited method where the parent class
298- #
308+ # sits in a different module
299309 log .warning (
300310 f"failed to find container { method .__module__ } .{ method_container !r} "
301311 f"of method { method .__name__ !r} "
0 commit comments