<s> """<STR_LIT>""" <EOL> import inspect <EOL> import re <EOL> from jedi . _compatibility import builtins <EOL> from jedi import debug <EOL> from jedi . common import source_to_unicode <EOL> from jedi . cache import underscore_memoization <EOL> from jedi . evaluate import compiled <EOL> from jedi . evaluate . compiled . fake import get_module <EOL> from jedi . parser import tree as pt <EOL> from jedi . parser import load_grammar <EOL> from jedi . parser . fast import FastParser <EOL> from jedi . evaluate import helpers <EOL> from jedi . evaluate import iterable <EOL> from jedi . evaluate import representation as er <EOL> def add_namespaces_to_parser ( evaluator , namespaces , parser_module ) : <EOL> for namespace in namespaces : <EOL> for key , value in namespace . items ( ) : <EOL> arr = parser_module . names_dict . setdefault ( key , [ ] ) <EOL> arr . append ( LazyName ( evaluator , parser_module , key , value ) ) <EOL> class LazyName ( helpers . FakeName ) : <EOL> def __init__ ( self , evaluator , module , name , value ) : <EOL> super ( LazyName , self ) . __init__ ( name ) <EOL> self . _module = module <EOL> self . _evaluator = evaluator <EOL> self . _value = value <EOL> self . _name = name <EOL> def is_definition ( self ) : <EOL> return True <EOL> @ property <EOL> @ underscore_memoization <EOL> def parent ( self ) : <EOL> """<STR_LIT>""" <EOL> obj = self . _value <EOL> parser_path = [ ] <EOL> if inspect . ismodule ( obj ) : <EOL> module = obj <EOL> else : <EOL> names = [ ] <EOL> try : <EOL> o = obj . __objclass__ <EOL> names . append ( obj . __name__ ) <EOL> obj = o <EOL> except AttributeError : <EOL> pass <EOL> try : <EOL> module_name = obj . __module__ <EOL> names . insert ( <NUM_LIT:0> , obj . __name__ ) <EOL> except AttributeError : <EOL> module = builtins <EOL> else : <EOL> module = __import__ ( module_name ) <EOL> parser_path = names <EOL> raw_module = get_module ( self . _value ) <EOL> found = [ ] <EOL> try : <EOL> path = module . __file__ <EOL> except AttributeError : <EOL> pass <EOL> else : <EOL> path = re . sub ( '<STR_LIT>' , '<STR_LIT>' , path ) <EOL> if path . endswith ( '<STR_LIT>' ) : <EOL> with open ( path ) as f : <EOL> source = source_to_unicode ( f . read ( ) ) <EOL> mod = FastParser ( load_grammar ( ) , source , path [ : - <NUM_LIT:1> ] ) . module <EOL> if parser_path : <EOL> assert len ( parser_path ) == <NUM_LIT:1> <EOL> found = self . _evaluator . find_types ( mod , parser_path [ <NUM_LIT:0> ] , search_global = True ) <EOL> else : <EOL> found = [ self . _evaluator . wrap ( mod ) ] <EOL> if not found : <EOL> debug . warning ( '<STR_LIT>' , <EOL> parser_path ) <EOL> if not found : <EOL> evaluated = compiled . CompiledObject ( obj ) <EOL> if evaluated == builtins : <EOL> evaluated = compiled . builtin <EOL> found = [ evaluated ] <EOL> content = iterable . AlreadyEvaluated ( found ) <EOL> stmt = pt . ExprStmt ( [ self , pt . Operator ( pt . zero_position_modifier , <EOL> '<STR_LIT:=>' , ( <NUM_LIT:0> , <NUM_LIT:0> ) , '<STR_LIT>' ) , content ] ) <EOL> stmt . parent = self . _module <EOL> return stmt <EOL> @ parent . setter <EOL> def parent ( self , value ) : <EOL> """<STR_LIT>""" </s>
