Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@memoize_default()
def names_dicts(self, search_global):
yield self._self_names_dict()
for s in self.base.py__mro__(self._evaluator)[1:]:
if not isinstance(s, compiled.CompiledObject):
# Compiled objects don't have `self.` names.
for inst in self._evaluator.execute(s):
yield inst._self_names_dict(add_mro=False)
for names_dict in self.base.names_dicts(search_global=False, is_instance=True):
yield LazyInstanceDict(self._evaluator, self, names_dict)
@memoize_default()
def defined_names(self):
"""
List sub-definitions (e.g., methods in class).
:rtype: list of Definition
"""
defs = self._follow_statements_imports()
# For now we don't want base classes or evaluate decorators.
defs = [d.base if isinstance(d, (er.Class, er.Function)) else d for d in defs]
iterable = (defined_names(self._evaluator, d) for d in defs)
iterable = list(iterable)
return list(chain.from_iterable(iterable))
@memoize_default()
def eval_node(self):
"""
The first part `x + 1` of the list comprehension:
[x + 1 for x in foo]
"""
comprehension = self._atom.children[1]
# For nested comprehensions we need to search the last one.
last = comprehension.children[-1]
last_comp = comprehension.children[1]
while True:
if isinstance(last, tree.CompFor):
last_comp = last
elif not tree.is_node(last, 'comp_if'):
break
last = last.children[-1]
@memoize_default()
def params(self):
"""
Raises an ``AttributeError``if the definition is not callable.
Otherwise returns a list of `Definition` that represents the params.
"""
followed = self._follow_statements_imports()
if not followed or not hasattr(followed[0], 'py__call__'):
raise AttributeError()
followed = followed[0] # only check the first one.
if followed.isinstance(er.Function):
if isinstance(followed, er.InstanceElement):
params = followed.params[1:]
else:
params = followed.params
elif followed.isinstance(er.compiled.CompiledObject):
@memoize_default()
def defined_names(self):
"""
List sub-definitions (e.g., methods in class).
:rtype: list of Definition
"""
defs = self._follow_statements_imports()
# For now we don't want base classes or evaluate decorators.
defs = [d.base if isinstance(d, (er.Class, er.Function)) else d for d in defs]
iterable = (defined_names(self._evaluator, d) for d in defs)
iterable = list(iterable)
return list(chain.from_iterable(iterable))
@memoize_default([], evaluator_is_first_arg=True)
@to_list
def _search_function_executions(evaluator, module_context, funcdef):
"""
Returns a list of param names.
"""
from jedi.evaluate import representation as er
func_string_name = funcdef.name.value
compare_node = funcdef
if func_string_name == '__init__':
cls = get_parent_scope(funcdef)
if isinstance(cls, tree.Class):
func_string_name = cls.name.value
compare_node = cls
found_executions = False
@memoize_default()
def _sub_modules_dict(self):
"""
Lists modules in the directory of this module (if this module is a
package).
"""
path = self._module.path
names = {}
if path is not None and path.endswith(os.path.sep + '__init__.py'):
mods = pkgutil.iter_modules([os.path.dirname(path)])
for module_loader, name, is_pkg in mods:
fake_n = helpers.FakeName(name)
# It's obviously a relative import to the current module.
imp = helpers.FakeImport(fake_n, self, level=1)
fake_n.parent = imp
names[name] = [fake_n]
@memoize_default(default=[])
@common.to_list
def _iterate(self):
comp_fors = tuple(self._get_comp_for().get_comp_fors())
for result in self._nested(comp_fors):
yield result
@memoize_default(default=NO_DEFAULT)
def get_params(self):
return param.get_params(self, self.var_args)
@common.safe_property
@memoize_default([])
def yields(self):
return tree.Scope._search_in_scope(self, tree.YieldExpr)