module documentation
(source)

Simple type inference for decorated functions during semantic analysis.
Function calculate​_return​_type Return the return type if we can calculate it.
Function find​_fixed​_callable​_return Return the return type, if expression refers to a callable that returns a callable.
Function infer​_decorator​_signature​_if​_simple Try to infer the type of the decorated function.
Function is​_identity​_signature Is type a callable of form T -> T (where T is a type variable)?
def calculate_return_type(expr): (source)

Return the return type if we can calculate it.

This only uses information available during semantic analysis so this will sometimes return None because of insufficient information (as type inference hasn't run yet).

Parameters
expr:ExpressionUndocumented
Returns
Optional[ProperType]Undocumented
def find_fixed_callable_return(expr): (source)

Return the return type, if expression refers to a callable that returns a callable.

But only do this if the return type has no type variables. Return None otherwise. This approximates things a lot as this is supposed to be called before type checking when full type information is not available yet.

Parameters
expr:ExpressionUndocumented
Returns
Optional[CallableType]Undocumented
def infer_decorator_signature_if_simple(dec, analyzer): (source)

Try to infer the type of the decorated function.

This lets us resolve additional references to decorated functions during type checking. Otherwise the type might not be available when we need it, since module top levels can't be deferred.

This basically uses a simple special-purpose type inference engine just for decorators.

Parameters
dec:DecoratorUndocumented
analyzer:SemanticAnalyzerInterfaceUndocumented
def is_identity_signature(sig): (source)
Is type a callable of form T -> T (where T is a type variable)?
Parameters
sig:TypeUndocumented
Returns
boolUndocumented