module documentation

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: Expression) -> ProperType|None: (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).

def find_fixed_callable_return(expr: Expression) -> CallableType|None: (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.

def infer_decorator_signature_if_simple(dec: Decorator, analyzer: SemanticAnalyzerInterface): (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.

def is_identity_signature(sig: Type) -> bool: (source)

Is type a callable of form T -> T (where T is a type variable)?