(execution_context, param)
return _evaluate_for_annotation(module_context, annotation)
Infers the type of a function parameter, using type annotations.
Infers the type of a function parameter, using type annotations.
Infers the type of a function parameter using type annotations .
def infer_param(execution_context, param):
    """
    Infers the type of a function parameter, using type annotations.
    """
    annotation = param.annotation
    if annotation is None:
        # If no Python 3-style annotation, look for a Python 2-style comment
        # annotation.
        # Identify parameters to function in the same sequence as they would
        # appear in a type comment.
        all_params = [child for child in param.parent.children
                      if child.type == 'param']

        node = param.parent.parent
        comment = parser_utils.get_following_comment_same_line(node)
        if comment is None:
            return NO_CONTEXTS

        match = re.match(r"^#\s*type:\s*\(([^#]*)\)\s*->", comment)
        if not match:
            return NO_CONTEXTS
        params_comments = _split_comment_param_declaration(match.group(1))

        # Find the specific param being investigated
        index = all_params.index(param)
        # If the number of parameters doesn't match length of type comment,
        # ignore first parameter (assume it's self).
        if len(params_comments) != len(all_params):
            debug.warning(
                "Comments length != Params length %s %s",
                params_comments, all_params
            )
        from jedi.evaluate.context.instance import BaseInstanceFunctionExecution
        if isinstance(execution_context, BaseInstanceFunctionExecution):
            if index == 0:
                # Assume it's self, which is already handled
                return NO_CONTEXTS
            index -= 1
        if index >= len(params_comments):
            return NO_CONTEXTS

        param_comment = params_comments[index]
        return _evaluate_annotation_string(
            execution_context.get_root_context(),
            param_comment
        )
    module_context = execution_context.get_root_context()
    return _evaluate_for_annotation(module_context, annotation)
def infer_param ( execution_context , param ) : annotation = param . annotation if annotation is None : # If no Python 3-style annotation, look for a Python 2-style comment # annotation. # Identify parameters to function in the same sequence as they would # appear in a type comment. all_params = [ child for child in param . parent . children if child . type == 'param' ] node = param . parent . parent comment = parser_utils . get_following_comment_same_line ( node ) if comment is None : return NO_CONTEXTS match = re . match ( r"^#\s*type:\s*\(([^#]*)\)\s*->" , comment ) if not match : return NO_CONTEXTS params_comments = _split_comment_param_declaration ( match . group ( 1 ) ) # Find the specific param being investigated index = all_params . index ( param ) # If the number of parameters doesn't match length of type comment, # ignore first parameter (assume it's self). if len ( params_comments ) != len ( all_params ) : debug . warning ( "Comments length != Params length %s %s" , params_comments , all_params ) from jedi . evaluate . context . instance import BaseInstanceFunctionExecution if isinstance ( execution_context , BaseInstanceFunctionExecution ) : if index == 0 : # Assume it's self, which is already handled return NO_CONTEXTS index -= 1 if index >= len ( params_comments ) : return NO_CONTEXTS param_comment = params_comments [ index ] return _evaluate_annotation_string ( execution_context . get_root_context ( ) , param_comment ) module_context = execution_context . get_root_context ( ) return _evaluate_for_annotation ( module_context , annotation )