<s> """<STR_LIT>""" <EOL> import warnings <EOL> from itertools import chain <EOL> import re <EOL> from jedi . _compatibility import unicode , use_metaclass <EOL> from jedi import settings <EOL> from jedi import common <EOL> from jedi . parser import tree <EOL> from jedi . evaluate . cache import memoize_default , CachedMetaClass <EOL> from jedi . evaluate import representation as er <EOL> from jedi . evaluate import iterable <EOL> from jedi . evaluate import imports <EOL> from jedi . evaluate import compiled <EOL> from jedi . api import keywords <EOL> from jedi . evaluate . finder import filter_definition_names <EOL> def defined_names ( evaluator , scope ) : <EOL> """<STR_LIT>""" <EOL> dct = scope . names_dict <EOL> names = list ( chain . from_iterable ( dct . values ( ) ) ) <EOL> names = filter_definition_names ( names , scope ) <EOL> return [ Definition ( evaluator , d ) for d in sorted ( names , key = lambda s : s . start_pos ) ] <EOL> class BaseDefinition ( object ) : <EOL> _mapping = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> _tuple_mapping = dict ( ( tuple ( k . split ( '<STR_LIT:.>' ) ) , v ) for ( k , v ) in { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } . items ( ) ) <EOL> def __init__ ( self , evaluator , name ) : <EOL> self . _evaluator = evaluator <EOL> self . _name = name <EOL> """<STR_LIT>""" <EOL> self . _definition = evaluator . wrap ( self . _name . get_definition ( ) ) <EOL> self . is_keyword = isinstance ( self . _definition , keywords . Keyword ) <EOL> self . _module = name . get_parent_until ( ) <EOL> if self . in_builtin_module ( ) : <EOL> self . module_path = None <EOL> else : <EOL> self . module_path = self . _module . path <EOL> """<STR_LIT>""" <EOL> @ property <EOL> def name ( self ) : <EOL> """<STR_LIT>""" <EOL> return unicode ( self . _name ) <EOL> @ property <EOL> def start_pos ( self ) : <EOL> """<STR_LIT>""" <EOL> warnings . warn ( "<STR_LIT>" , DeprecationWarning ) <EOL> return self . _name . start_pos <EOL> @ property <EOL> def type ( self ) : <EOL> """<STR_LIT>""" <EOL> stripped = self . _definition <EOL> if isinstance ( stripped , er . InstanceElement ) : <EOL> stripped = stripped . var <EOL> if isinstance ( stripped , compiled . CompiledObject ) : <EOL> return stripped . api_type ( ) <EOL> elif isinstance ( stripped , iterable . Array ) : <EOL> return '<STR_LIT>' <EOL> elif isinstance ( stripped , tree . Import ) : <EOL> return '<STR_LIT>' <EOL> string = type ( stripped ) . __name__ . lower ( ) . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if string == '<STR_LIT>' : <EOL> return '<STR_LIT>' <EOL> else : <EOL> return string <EOL> def _path ( self ) : <EOL> """<STR_LIT>""" <EOL> path = [ ] <EOL> par = self . _definition <EOL> while par is not None : <EOL> if isinstance ( par , tree . Import ) : <EOL> path += imports . ImportWrapper ( self . _evaluator , self . _name ) . import_path <EOL> break <EOL> try : <EOL> name = par . name <EOL> except AttributeError : <EOL> pass <EOL> else : <EOL> if isinstance ( par , er . ModuleWrapper ) : <EOL> path [ <NUM_LIT:0> : <NUM_LIT:0> ] = par . py__name__ ( ) . split ( '<STR_LIT:.>' ) <EOL> break <EOL> else : <EOL> path . insert ( <NUM_LIT:0> , unicode ( name ) ) <EOL> par = par . parent <EOL> return path <EOL> @ property <EOL> def module_name ( self ) : <EOL> """<STR_LIT>""" <EOL> return str ( self . _module . name ) <EOL> def in_builtin_module ( self ) : <EOL> """<STR_LIT>""" <EOL> return isinstance ( self . _module , compiled . CompiledObject ) <EOL> @ property <EOL> def line ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . in_builtin_module ( ) : <EOL> return None <EOL> return self . _name . start_pos [ <NUM_LIT:0> ] <EOL> @ property <EOL> def column ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . in_builtin_module ( ) : <EOL> return None <EOL> return self . _name . start_pos [ <NUM_LIT:1> ] <EOL> def docstring ( self , raw = False ) : <EOL> r"""<STR_LIT>""" <EOL> if raw : <EOL> return _Help ( self . _definition ) . raw ( ) <EOL> else : <EOL> return _Help ( self . _definition ) . full ( ) <EOL> @ property <EOL> def doc ( self ) : <EOL> """<STR_LIT>""" <EOL> warnings . warn ( "<STR_LIT>" , DeprecationWarning ) <EOL> return self . docstring ( ) <EOL> @ property <EOL> def raw_doc ( self ) : <EOL> """<STR_LIT>""" <EOL> warnings . warn ( "<STR_LIT>" , DeprecationWarning ) <EOL> return self . docstring ( raw = True ) <EOL> @ property <EOL> def description ( self ) : <EOL> """<STR_LIT>""" <EOL> return unicode ( self . _name ) <EOL> @ property <EOL> def full_name ( self ) : <EOL> """<STR_LIT>""" <EOL> path = [ unicode ( p ) for p in self . _path ( ) ] <EOL> if not path : <EOL> return None <EOL> with common . ignored ( KeyError ) : <EOL> path [ <NUM_LIT:0> ] = self . _mapping [ path [ <NUM_LIT:0> ] ] <EOL> for key , repl in self . _tuple_mapping . items ( ) : <EOL> if tuple ( path [ : len ( key ) ] ) == key : <EOL> path = [ repl ] + path [ len ( key ) : ] <EOL> return '<STR_LIT:.>' . join ( path if path [ <NUM_LIT:0> ] else path [ <NUM_LIT:1> : ] ) <EOL> def goto_assignments ( self ) : <EOL> defs = self . _evaluator . goto ( self . _name ) <EOL> return [ Definition ( self . _evaluator , d ) for d in defs ] <EOL> @ memoize_default ( ) <EOL> def _follow_statements_imports ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . _definition . isinstance ( tree . ExprStmt ) : <EOL> return self . _evaluator . eval_statement ( self . _definition ) <EOL> elif self . _definition . isinstance ( tree . Import ) : <EOL> return imports . ImportWrapper ( self . _evaluator , self . _name ) . follow ( ) <EOL> else : <EOL> return [ self . _definition ] <EOL> @ property <EOL> @ memoize_default ( ) <EOL> def params ( self ) : <EOL> """<STR_LIT>""" <EOL> followed = self . _follow_statements_imports ( ) <EOL> if not followed or not hasattr ( followed [ <NUM_LIT:0> ] , '<STR_LIT>' ) : <EOL> raise AttributeError ( ) <EOL> followed = followed [ <NUM_LIT:0> ] <EOL> if followed . type == '<STR_LIT>' : <EOL> if isinstance ( followed , er . InstanceElement ) : <EOL> params = followed . params [ <NUM_LIT:1> : ] <EOL> else : <EOL> params = followed . params <EOL> elif followed . isinstance ( er . compiled . CompiledObject ) : <EOL> params = followed . params <EOL> else : <EOL> try : <EOL> sub = followed . get_subscope_by_name ( '<STR_LIT>' ) <EOL> params = sub . params [ <NUM_LIT:1> : ] <EOL> except KeyError : <EOL> return [ ] <EOL> return [ _Param ( self . _evaluator , p . name ) for p in params ] <EOL> def parent ( self ) : <EOL> scope = self . _definition . get_parent_scope ( ) <EOL> scope = self . _evaluator . wrap ( scope ) <EOL> return Definition ( self . _evaluator , scope . name ) <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % ( type ( self ) . __name__ , self . description ) <EOL> class Completion ( BaseDefinition ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , evaluator , name , needs_dot , like_name_length ) : <EOL> super ( Completion , self ) . __init__ ( evaluator , name ) <EOL> self . _needs_dot = needs_dot <EOL> self . _like_name_length = like_name_length <EOL> self . _same_name_completions = [ ] <EOL> def _complete ( self , like_name ) : <EOL> dot = '<STR_LIT:.>' if self . _needs_dot else '<STR_LIT>' <EOL> append = '<STR_LIT>' <EOL> if settings . add_bracket_after_function and self . type == '<STR_LIT>' : <EOL> append = '<STR_LIT:(>' <EOL> if settings . add_dot_after_module : <EOL> if isinstance ( self . _definition , tree . Module ) : <EOL> append += '<STR_LIT:.>' <EOL> if isinstance ( self . _definition , tree . Param ) : <EOL> append += '<STR_LIT:=>' <EOL> name = str ( self . _name ) <EOL> if like_name : <EOL> name = name [ self . _like_name_length : ] <EOL> return dot + name + append <EOL> @ property <EOL> def complete ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _complete ( True ) <EOL> @ property <EOL> def name_with_symbols ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _complete ( False ) <EOL> @ property <EOL> def description ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . _definition is None : <EOL> return '<STR_LIT>' <EOL> t = self . type <EOL> if t == '<STR_LIT>' or t == '<STR_LIT>' : <EOL> desc = self . _definition . get_code ( ) <EOL> else : <EOL> desc = '<STR_LIT:.>' . join ( unicode ( p ) for p in self . _path ( ) ) <EOL> line = '<STR_LIT>' if self . in_builtin_module else '<STR_LIT>' % self . line <EOL> return '<STR_LIT>' % ( t , desc , line ) <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( type ( self ) . __name__ , self . _name ) <EOL> def docstring ( self , raw = False , fast = True ) : <EOL> """<STR_LIT>""" <EOL> definition = self . _definition <EOL> if isinstance ( definition , tree . Import ) : <EOL> i = imports . ImportWrapper ( self . _evaluator , self . _name ) <EOL> if len ( i . import_path ) > <NUM_LIT:1> or not fast : <EOL> followed = self . _follow_statements_imports ( ) <EOL> if followed : <EOL> definition = followed [ <NUM_LIT:0> ] <EOL> if raw : <EOL> return _Help ( definition ) . raw ( ) <EOL> else : <EOL> return _Help ( definition ) . full ( ) <EOL> @ property <EOL> def type ( self ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( self . _definition , tree . Import ) : <EOL> i = imports . ImportWrapper ( self . _evaluator , self . _name ) <EOL> if len ( i . import_path ) <= <NUM_LIT:1> : <EOL> return '<STR_LIT>' <EOL> followed = self . follow_definition ( ) <EOL> if followed : <EOL> return followed [ <NUM_LIT:0> ] . type <EOL> return super ( Completion , self ) . type <EOL> @ memoize_default ( ) <EOL> def _follow_statements_imports ( self ) : <EOL> definition = self . _definition <EOL> if definition . isinstance ( tree . Import ) : <EOL> i = imports . ImportWrapper ( self . _evaluator , self . _name ) <EOL> return i . follow ( ) <EOL> return super ( Completion , self ) . _follow_statements_imports ( ) <EOL> @ memoize_default ( ) <EOL> def follow_definition ( self ) : <EOL> """<STR_LIT>""" <EOL> defs = self . _follow_statements_imports ( ) <EOL> return [ Definition ( self . _evaluator , d . name ) for d in defs ] <EOL> class Definition ( use_metaclass ( CachedMetaClass , BaseDefinition ) ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , evaluator , definition ) : <EOL> super ( Definition , self ) . __init__ ( evaluator , definition ) <EOL> @ property <EOL> def description ( self ) : <EOL> """<STR_LIT>""" <EOL> d = self . _definition <EOL> if isinstance ( d , er . InstanceElement ) : <EOL> d = d . var <EOL> if isinstance ( d , compiled . CompiledObject ) : <EOL> typ = d . api_type ( ) <EOL> if typ == '<STR_LIT>' : <EOL> typ = '<STR_LIT:class>' <EOL> d = typ + '<STR_LIT:U+0020>' + d . name . get_code ( ) <EOL> elif isinstance ( d , iterable . Array ) : <EOL> d = '<STR_LIT>' + d . type <EOL> elif isinstance ( d , ( tree . Class , er . Class , er . Instance ) ) : <EOL> d = '<STR_LIT>' + unicode ( d . name ) <EOL> elif isinstance ( d , ( er . Function , tree . Function ) ) : <EOL> d = '<STR_LIT>' + unicode ( d . name ) <EOL> elif isinstance ( d , tree . Module ) : <EOL> d = '<STR_LIT>' % self . module_name <EOL> elif isinstance ( d , tree . Param ) : <EOL> d = d . get_code ( ) . strip ( ) <EOL> if d . endswith ( '<STR_LIT:U+002C>' ) : <EOL> d = d [ : - <NUM_LIT:1> ] <EOL> else : <EOL> try : <EOL> first_leaf = d . first_leaf ( ) <EOL> except AttributeError : <EOL> first_leaf = d <EOL> old , first_leaf . prefix = first_leaf . prefix , '<STR_LIT>' <EOL> try : <EOL> d = d . get_code ( ) <EOL> finally : <EOL> first_leaf . prefix = old <EOL> d = re . sub ( '<STR_LIT>' , '<STR_LIT:U+0020>' , d ) <EOL> return re . sub ( '<STR_LIT>' , '<STR_LIT:U+0020>' , d ) . strip ( ) <EOL> @ property <EOL> def desc_with_module ( self ) : <EOL> """<STR_LIT>""" <EOL> position = '<STR_LIT>' if self . in_builtin_module else '<STR_LIT>' % ( self . line ) <EOL> return "<STR_LIT>" % ( self . module_name , self . description , position ) <EOL> @ memoize_default ( ) <EOL> def defined_names ( self ) : <EOL> """<STR_LIT>""" <EOL> defs = self . _follow_statements_imports ( ) <EOL> defs = [ d . base if isinstance ( d , ( er . Class , er . Function ) ) else d for d in defs ] <EOL> iterable = ( defined_names ( self . _evaluator , d ) for d in defs ) <EOL> iterable = list ( iterable ) <EOL> return list ( chain . from_iterable ( iterable ) ) <EOL> def is_definition ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _name . is_definition ( ) <EOL> def __eq__ ( self , other ) : <EOL> return self . _name . start_pos == other . _name . start_pos and self . module_path == other . module_path and self . name == other . name and self . _evaluator == other . _evaluator <EOL> def __ne__ ( self , other ) : <EOL> return not self . __eq__ ( other ) <EOL> def __hash__ ( self ) : <EOL> return hash ( ( self . _name . start_pos , self . module_path , self . name , self . _evaluator ) ) <EOL> class CallSignature ( Definition ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , evaluator , executable_name , call_stmt , index , key_name ) : <EOL> super ( CallSignature , self ) . __init__ ( evaluator , executable_name ) <EOL> self . _index = index <EOL> self . _key_name = key_name <EOL> self . _call_stmt = call_stmt <EOL> @ property <EOL> def index ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . _key_name is not None : <EOL> for i , param in enumerate ( self . params ) : <EOL> if self . _key_name == param . name : <EOL> return i <EOL> if self . params and self . params [ - <NUM_LIT:1> ] . _name . get_definition ( ) . stars == <NUM_LIT:2> : <EOL> return i <EOL> else : <EOL> return None <EOL> if self . _index >= len ( self . params ) : <EOL> for i , param in enumerate ( self . params ) : <EOL> if param . _name . get_definition ( ) . stars == <NUM_LIT:1> : <EOL> return i <EOL> return None <EOL> return self . _index <EOL> @ property <EOL> def bracket_start ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _call_stmt . end_pos <EOL> @ property <EOL> def call_name ( self ) : <EOL> """<STR_LIT>""" <EOL> warnings . warn ( "<STR_LIT>" , DeprecationWarning ) <EOL> return unicode ( self . name ) <EOL> @ property <EOL> def module ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _executable . get_parent_until ( ) <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( type ( self ) . __name__ , self . _name , <EOL> self . index ) <EOL> class _Param ( Definition ) : <EOL> """<STR_LIT>""" <EOL> def get_code ( self ) : <EOL> """<STR_LIT>""" <EOL> warnings . warn ( "<STR_LIT>" , DeprecationWarning ) <EOL> return self . description <EOL> class _Help ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , definition ) : <EOL> self . _name = definition <EOL> def full ( self ) : <EOL> try : <EOL> return self . _name . doc <EOL> except AttributeError : <EOL> return self . raw ( ) <EOL> def raw ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return self . _name . raw_doc <EOL> except AttributeError : <EOL> return '<STR_LIT>' </s>
