<s> """<STR_LIT>""" <EOL> import re <EOL> from itertools import chain <EOL> from textwrap import dedent <EOL> from jedi . evaluate . cache import memoize_default <EOL> from jedi . parser import Parser <EOL> from jedi . common import indent_block <EOL> DOCSTRING_PARAM_PATTERNS = [ <EOL> r'<STR_LIT>' , <EOL> r'<STR_LIT>' , <EOL> ] <EOL> DOCSTRING_RETURN_PATTERNS = [ <EOL> re . compile ( r'<STR_LIT>' , re . M ) , <EOL> re . compile ( r'<STR_LIT>' , re . M ) , <EOL> ] <EOL> REST_ROLE_PATTERN = re . compile ( r'<STR_LIT>' ) <EOL> @ memoize_default ( None , evaluator_is_first_arg = True ) <EOL> def follow_param ( evaluator , param ) : <EOL> func = param . parent_function <EOL> param_str = _search_param_in_docstr ( func . raw_doc , str ( param . get_name ( ) ) ) <EOL> return _evaluate_for_statement_string ( evaluator , param_str , param . get_parent_until ( ) ) <EOL> def _search_param_in_docstr ( docstr , param_str ) : <EOL> """<STR_LIT>""" <EOL> patterns = [ re . compile ( p % re . escape ( param_str ) ) <EOL> for p in DOCSTRING_PARAM_PATTERNS ] <EOL> for pattern in patterns : <EOL> match = pattern . search ( docstr ) <EOL> if match : <EOL> return _strip_rst_role ( match . group ( <NUM_LIT:1> ) ) <EOL> return None <EOL> def _strip_rst_role ( type_str ) : <EOL> """<STR_LIT>""" <EOL> match = REST_ROLE_PATTERN . match ( type_str ) <EOL> if match : <EOL> return match . group ( <NUM_LIT:1> ) <EOL> else : <EOL> return type_str <EOL> def _evaluate_for_statement_string ( evaluator , string , module ) : <EOL> code = dedent ( """<STR_LIT>""" ) <EOL> if string is None : <EOL> return [ ] <EOL> for element in re . findall ( '<STR_LIT>' , string ) : <EOL> string = '<STR_LIT>' % element + string <EOL> p = Parser ( code % indent_block ( string ) , no_docstr = True ) <EOL> pseudo_cls = p . module . subscopes [ <NUM_LIT:0> ] <EOL> try : <EOL> stmt = pseudo_cls . statements [ - <NUM_LIT:1> ] <EOL> except IndexError : <EOL> return [ ] <EOL> pseudo_cls . parent = module <EOL> definitions = evaluator . eval_statement ( stmt ) <EOL> it = ( evaluator . execute ( d ) for d in definitions ) <EOL> return list ( chain . from_iterable ( it ) ) or definitions <EOL> @ memoize_default ( None , evaluator_is_first_arg = True ) <EOL> def find_return_types ( evaluator , func ) : <EOL> def search_return_in_docstr ( code ) : <EOL> for p in DOCSTRING_RETURN_PATTERNS : <EOL> match = p . search ( code ) <EOL> if match : <EOL> return _strip_rst_role ( match . group ( <NUM_LIT:1> ) ) <EOL> type_str = search_return_in_docstr ( func . raw_doc ) <EOL> return _evaluate_for_statement_string ( evaluator , type_str , func . get_parent_until ( ) ) </s>
