Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _is_local(pyname):
module, lineno = pyname.get_definition_location()
if lineno is None:
return False
scope = module.get_scope().get_inner_scope_for_line(lineno)
if isinstance(pyname, pynames.DefinedName) and \
scope.get_kind() in ('Function', 'Class'):
scope = scope.parent
return scope.get_kind() == 'Function' and \
pyname in scope.get_names().values() and \
isinstance(pyname, pynames.AssignedName)
def element_already_exists(self):
if self.pyname is None or isinstance(self.pyname, pynames.UnboundName):
return False
return self.get_name() in self.goal_scope.get_defined_names()
def _get_pyname(pycore, resource, offset):
pymodule = pycore.resource_to_pyobject(resource)
pyname = evaluate.eval_location(pymodule, offset)
if isinstance(pyname, pynames.ImportedName):
pyname = pyname._get_imported_pyname()
return pyname
def _follow_pyname(assignment, pymodule, lineno=None):
assign_node = assignment.ast_node
if lineno is None:
lineno = _get_lineno_for_node(assign_node)
holding_scope = pymodule.get_scope().get_inner_scope_for_line(lineno)
pyname = evaluate.eval_node(holding_scope, assign_node)
if pyname is not None:
result = pyname.get_object()
if isinstance(result.get_type(), rope.base.builtins.Property) and \
holding_scope.get_kind() == 'Class':
arg = rope.base.pynames.UnboundName(
rope.base.pyobjects.PyObject(holding_scope.pyobject))
return pyname, result.get_type().get_property_object(
arguments.ObjectArguments([arg]))
return pyname, result
def parameters(self):
"""The names of the parameters the function takes.
Returns None if this completion is not a function.
"""
pyname = self.pyname
if isinstance(pyname, pynames.ImportedName):
pyname = pyname._get_imported_pyname()
if isinstance(pyname, pynames.DefinedName):
pyobject = pyname.get_object()
if isinstance(pyobject, pyobjects.AbstractFunction):
return pyobject.get_param_names()
def _add_names(self, pymodule, modname, underlined):
if underlined is None:
underlined = self.underlined
globals = []
if isinstance(pymodule, pyobjects.PyDefinedObject):
attributes = pymodule._get_structural_attributes()
else:
attributes = pymodule.get_attributes()
for name, pyname in attributes.items():
if not underlined and name.startswith('_'):
continue
if isinstance(pyname, (pynames.AssignedName, pynames.DefinedName)):
globals.append(name)
if isinstance(pymodule, builtins.BuiltinModule):
globals.append(name)
self.names[modname] = globals
def _is_local(pyname):
module, lineno = pyname.get_definition_location()
if lineno is None:
return False
scope = module.get_scope().get_inner_scope_for_line(lineno)
if isinstance(pyname, pynames.DefinedName) and \
scope.get_kind() in ('Function', 'Class'):
scope = scope.parent
return scope.get_kind() == 'Function' and \
pyname in scope.get_names().values() and \
isinstance(pyname, pynames.AssignedName)
def _is_local(pyname):
module, lineno = pyname.get_definition_location()
if lineno is None:
return False
scope = module.get_scope().get_inner_scope_for_line(lineno)
if isinstance(pyname, pynames.DefinedName) and \
scope.get_kind() in ('Function', 'Class'):
scope = scope.parent
return scope.get_kind() == 'Function' and \
pyname in list(scope.get_names().values()) and \
isinstance(pyname, pynames.AssignedName)
def _get_scope_and_pyname(self, pyname):
if pyname is not None and isinstance(pyname, pynames.AssignedName):
pymodule, lineno = pyname.get_definition_location()
if pymodule is None:
return None, None
if lineno is None:
lineno = 1
scope = pymodule.get_scope().get_inner_scope_for_line(lineno)
name = None
while name is None and scope is not None:
for current in scope.get_names():
if scope[current] is pyname:
name = current
break
else:
scope = scope.parent
return scope, name
return None, None
def _get_scope(self, scope):
if isinstance(self.pyname, builtins.BuiltinName):
return 'builtin'
if isinstance(self.pyname, pynames.ImportedModule) or \
isinstance(self.pyname, pynames.ImportedName):
return 'imported'
return scope