Get rid of manual consumer fn unwrapping for callgraph generation
This commit is contained in:
@@ -14,19 +14,16 @@ class GraphWalker:
|
||||
from_types: frozenset[type],
|
||||
consumer_fn: Callable) -> Optional[Callgraph]:
|
||||
|
||||
into_types: frozenset[type] = extract_func_argtypes(consumer_fn)
|
||||
|
||||
branches: frozenset[Callgraph] = frozenset()
|
||||
|
||||
for into_type in into_types:
|
||||
cg = cls.generate_callgraph_singletype(injectors, from_types, into_type)
|
||||
if cg is None:
|
||||
return None
|
||||
branches |= {cg}
|
||||
variant = CallgraphVariant(
|
||||
ConversionPoint.from_fn(consumer_fn, NoneType)[0],
|
||||
branches, frozenset())
|
||||
return Callgraph(frozenset({variant}))
|
||||
# Хак, чтобы вынудить систему поставить первым преобразованием требуемый consumer
|
||||
# Новый TypeAliasType каждый раз будет иметь эксклюзивный хэш, вне зависимости от содержимого
|
||||
# При этом, TypeAliasType также выступает в роли ключа преобразования
|
||||
# Это позволяет переложить обработку аргументов consumer на внутренние механизмы построения графа преобразований
|
||||
type _tmp_type_for_consumer = object
|
||||
injectors |= set(ConversionPoint.from_fn(consumer_fn, _tmp_type_for_consumer))
|
||||
|
||||
return cls.generate_callgraph_singletype(injectors, from_types, _tmp_type_for_consumer)
|
||||
|
||||
@classmethod
|
||||
def generate_callgraph_singletype(cls,
|
||||
|
||||
@@ -39,7 +39,7 @@ class ConversionPoint:
|
||||
return inspect.iscoroutinefunction(self.fn) or is_async_context_manager_factory(self.fn)
|
||||
|
||||
@classmethod
|
||||
def from_fn(cls, func: Callable, rettype: Optional[type] = None):
|
||||
def from_fn(cls, func: Callable, rettype: Optional[type] = None) -> list[ConversionPoint]:
|
||||
if rettype is None:
|
||||
annot = get_type_hints(func)
|
||||
rettype = annot.get('return')
|
||||
|
||||
Reference in New Issue
Block a user