Show More
@@ -1,3 +1,4 b'' | |||||
|
1 | from inspect import signature | |||
1 | from typing import ( |
|
2 | from typing import ( | |
2 | Any, |
|
3 | Any, | |
3 | Callable, |
|
4 | Callable, | |
@@ -415,6 +416,11 b' UNARY_OP_DUNDERS: Dict[Type[ast.unaryop], Tuple[str, ...]] = {' | |||||
415 | } |
|
416 | } | |
416 |
|
417 | |||
417 |
|
418 | |||
|
419 | class Duck: | |||
|
420 | """A dummy class used to create objects of other classes without calling their __init__""" | |||
|
421 | pass | |||
|
422 | ||||
|
423 | ||||
418 | def _find_dunder(node_op, dunders) -> Union[Tuple[str, ...], None]: |
|
424 | def _find_dunder(node_op, dunders) -> Union[Tuple[str, ...], None]: | |
419 | dunder = None |
|
425 | dunder = None | |
420 | for op, candidate_dunder in dunders.items(): |
|
426 | for op, candidate_dunder in dunders.items(): | |
@@ -584,6 +590,13 b' def eval_node(node: Union[ast.AST, None], context: EvaluationContext):' | |||||
584 | if policy.can_call(func) and not node.keywords: |
|
590 | if policy.can_call(func) and not node.keywords: | |
585 | args = [eval_node(arg, context) for arg in node.args] |
|
591 | args = [eval_node(arg, context) for arg in node.args] | |
586 | return func(*args) |
|
592 | return func(*args) | |
|
593 | sig = signature(func) | |||
|
594 | # if annotation was not stringized, or it was stringized | |||
|
595 | # but resolved by signature call we know the return type | |||
|
596 | if not isinstance(sig.return_annotation, str): | |||
|
597 | duck = Duck() | |||
|
598 | duck.__class__ = sig.return_annotation | |||
|
599 | return duck | |||
587 | raise GuardRejection( |
|
600 | raise GuardRejection( | |
588 | "Call for", |
|
601 | "Call for", | |
589 | func, # not joined to avoid calling `repr` |
|
602 | func, # not joined to avoid calling `repr` |
General Comments 0
You need to be logged in to leave comments.
Login now