本文整理汇总了Python中jedi.evaluate.base_context.ContextSet.from_sets方法的典型用法代码示例。如果您正苦于以下问题:Python ContextSet.from_sets方法的具体用法?Python ContextSet.from_sets怎么用?Python ContextSet.from_sets使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jedi.evaluate.base_context.ContextSet
的用法示例。
在下文中一共展示了ContextSet.from_sets方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: builtins_isinstance
# 需要导入模块: from jedi.evaluate.base_context import ContextSet [as 别名]
# 或者: from jedi.evaluate.base_context.ContextSet import from_sets [as 别名]
def builtins_isinstance(evaluator, objects, types, arguments):
bool_results = set()
for o in objects:
try:
mro_func = o.py__class__().py__mro__
except AttributeError:
# This is temporary. Everything should have a class attribute in
# Python?! Maybe we'll leave it here, because some numpy objects or
# whatever might not.
return ContextSet(compiled.create(True), compiled.create(False))
mro = mro_func()
for cls_or_tup in types:
if cls_or_tup.is_class():
bool_results.add(cls_or_tup in mro)
elif cls_or_tup.name.string_name == 'tuple' \
and cls_or_tup.get_root_context() == evaluator.BUILTINS:
# Check for tuples.
classes = ContextSet.from_sets(
lazy_context.infer()
for lazy_context in cls_or_tup.iterate()
)
bool_results.add(any(cls in mro for cls in classes))
else:
_, lazy_context = list(arguments.unpack())[1]
if isinstance(lazy_context, LazyTreeContext):
node = lazy_context.data
message = 'TypeError: isinstance() arg 2 must be a ' \
'class, type, or tuple of classes and types, ' \
'not %s.' % cls_or_tup
analysis.add(lazy_context._context, 'type-error-isinstance', node, message)
return ContextSet.from_iterable(compiled.create(evaluator, x) for x in bool_results)
示例2: get_return_values
# 需要导入模块: from jedi.evaluate.base_context import ContextSet [as 别名]
# 或者: from jedi.evaluate.base_context.ContextSet import from_sets [as 别名]
def get_return_values(self, check_yields=False):
funcdef = self.tree_node
if funcdef.type == 'lambdef':
return self.eval_node(funcdef.children[-1])
if check_yields:
context_set = NO_CONTEXTS
returns = get_yield_exprs(self.evaluator, funcdef)
else:
returns = funcdef.iter_return_stmts()
context_set = docstrings.infer_return_types(self.function_context)
context_set |= pep0484.infer_return_types(self.function_context)
for r in returns:
check = flow_analysis.reachability_check(self, funcdef, r)
if check is flow_analysis.UNREACHABLE:
debug.dbg('Return unreachable: %s', r)
else:
if check_yields:
context_set |= ContextSet.from_sets(
lazy_context.infer()
for lazy_context in self._get_yield_lazy_context(r)
)
else:
try:
children = r.children
except AttributeError:
ctx = compiled.builtin_from_name(self.evaluator, u'None')
context_set |= ContextSet(ctx)
else:
context_set |= self.eval_node(children[1])
if check is flow_analysis.REACHABLE:
debug.dbg('Return reachable: %s', r)
break
return context_set
示例3: infer
# 需要导入模块: from jedi.evaluate.base_context import ContextSet [as 别名]
# 或者: from jedi.evaluate.base_context.ContextSet import from_sets [as 别名]
def infer(self):
with recursion.execution_allowed(self.evaluator, self) as allowed:
# We need to catch recursions that may occur, because an
# anonymous functions can create an anonymous parameter that is
# more or less self referencing.
if allowed:
return ContextSet.from_sets(p.infer() for p in self._executed_params)
return NO_CONTEXTS
示例4: py__getitem__
# 需要导入模块: from jedi.evaluate.base_context import ContextSet [as 别名]
# 或者: from jedi.evaluate.base_context.ContextSet import from_sets [as 别名]
def py__getitem__(context, typ, node):
if not typ.get_root_context().name.string_name == "typing":
return None
# we assume that any class using [] in a module called
# "typing" with a name for which we have a replacement
# should be replaced by that class. This is not 100%
# airtight but I don't have a better idea to check that it's
# actually the PEP-0484 typing module and not some other
if node.type == "subscriptlist":
nodes = node.children[::2] # skip the commas
else:
nodes = [node]
del node
nodes = [_fix_forward_reference(context, node) for node in nodes]
type_name = typ.name.string_name
# hacked in Union and Optional, since it's hard to do nicely in parsed code
if type_name in ("Union", '_Union'):
# In Python 3.6 it's still called typing.Union but it's an instance
# called _Union.
return ContextSet.from_sets(context.eval_node(node) for node in nodes)
if type_name in ("Optional", '_Optional'):
# Here we have the same issue like in Union. Therefore we also need to
# check for the instance typing._Optional (Python 3.6).
return context.eval_node(nodes[0])
module_node, code_lines = _get_typing_replacement_module(context.evaluator.latest_grammar)
typing = ModuleContext(
context.evaluator,
module_node=module_node,
path=None,
code_lines=code_lines,
)
factories = typing.py__getattribute__("factory")
assert len(factories) == 1
factory = list(factories)[0]
assert factory
function_body_nodes = factory.tree_node.children[4].children
valid_classnames = set(child.name.value
for child in function_body_nodes
if isinstance(child, tree.Class))
if type_name not in valid_classnames:
return None
compiled_classname = compiled.create_simple_object(context.evaluator, type_name)
from jedi.evaluate.context.iterable import FakeSequence
args = FakeSequence(
context.evaluator,
u'tuple',
[LazyTreeContext(context, n) for n in nodes]
)
result = factory.execute_evaluated(compiled_classname, args)
return result
示例5: _execute_types_in_stmt
# 需要导入模块: from jedi.evaluate.base_context import ContextSet [as 别名]
# 或者: from jedi.evaluate.base_context.ContextSet import from_sets [as 别名]
def _execute_types_in_stmt(module_context, stmt):
"""
Executing all types or general elements that we find in a statement. This
doesn't include tuple, list and dict literals, because the stuff they
contain is executed. (Used as type information).
"""
definitions = module_context.eval_node(stmt)
return ContextSet.from_sets(
_execute_array_values(module_context.evaluator, d)
for d in definitions
)
示例6: _execute_array_values
# 需要导入模块: from jedi.evaluate.base_context import ContextSet [as 别名]
# 或者: from jedi.evaluate.base_context.ContextSet import from_sets [as 别名]
def _execute_array_values(evaluator, array):
"""
Tuples indicate that there's not just one return value, but the listed
ones. `(str, int)` means that it returns a tuple with both types.
"""
from jedi.evaluate.context.iterable import SequenceLiteralContext, FakeSequence
if isinstance(array, SequenceLiteralContext):
values = []
for lazy_context in array.py__iter__():
objects = ContextSet.from_sets(
_execute_array_values(evaluator, typ)
for typ in lazy_context.infer()
)
values.append(LazyKnownContexts(objects))
return set([FakeSequence(evaluator, array.array_type, values)])
else:
return array.execute_evaluated()
示例7: _eval_comparison
# 需要导入模块: from jedi.evaluate.base_context import ContextSet [as 别名]
# 或者: from jedi.evaluate.base_context.ContextSet import from_sets [as 别名]
def _eval_comparison(evaluator, context, left_contexts, operator, right_contexts):
if not left_contexts or not right_contexts:
# illegal slices e.g. cause left/right_result to be None
result = (left_contexts or NO_CONTEXTS) | (right_contexts or NO_CONTEXTS)
return _literals_to_types(evaluator, result)
else:
# I don't think there's a reasonable chance that a string
# operation is still correct, once we pass something like six
# objects.
if len(left_contexts) * len(right_contexts) > 6:
return _literals_to_types(evaluator, left_contexts | right_contexts)
else:
return ContextSet.from_sets(
_eval_comparison_part(evaluator, context, left, operator, right)
for left in left_contexts
for right in right_contexts
)
示例8: builtins_next
# 需要导入模块: from jedi.evaluate.base_context import ContextSet [as 别名]
# 或者: from jedi.evaluate.base_context.ContextSet import from_sets [as 别名]
def builtins_next(evaluator, iterators, defaults):
"""
TODO this function is currently not used. It's a stab at implementing next
in a different way than fake objects. This would be a bit more flexible.
"""
if evaluator.environment.version_info.major == 2:
name = 'next'
else:
name = '__next__'
context_set = NO_CONTEXTS
for iterator in iterators:
if isinstance(iterator, AbstractInstanceContext):
context_set = ContextSet.from_sets(
n.infer()
for filter in iterator.get_filters(include_self_names=True)
for n in filter.get(name)
).execute_evaluated()
if context_set:
return context_set
return defaults
示例9: _names_to_types
# 需要导入模块: from jedi.evaluate.base_context import ContextSet [as 别名]
# 或者: from jedi.evaluate.base_context.ContextSet import from_sets [as 别名]
def _names_to_types(self, names, attribute_lookup):
contexts = ContextSet.from_sets(name.infer() for name in names)
debug.dbg('finder._names_to_types: %s -> %s', names, contexts)
if not names and isinstance(self._context, AbstractInstanceContext):
# handling __getattr__ / __getattribute__
return self._check_getattr(self._context)
# Add isinstance and other if/assert knowledge.
if not contexts and isinstance(self._name, tree.Name) and \
not isinstance(self._name_context, AbstractInstanceContext):
flow_scope = self._name
base_node = self._name_context.tree_node
if base_node.type == 'comp_for':
return contexts
while True:
flow_scope = get_parent_scope(flow_scope, include_flows=True)
n = _check_flow_information(self._name_context, flow_scope,
self._name, self._position)
if n is not None:
return n
if flow_scope == base_node:
break
return contexts
示例10: py__next__
# 需要导入模块: from jedi.evaluate.base_context import ContextSet [as 别名]
# 或者: from jedi.evaluate.base_context.ContextSet import from_sets [as 别名]
def py__next__(self):
# TODO add TypeError if params are given.
return ContextSet.from_sets(lazy_context.infer() for lazy_context in self.py__iter__())
示例11: dict_values
# 需要导入模块: from jedi.evaluate.base_context import ContextSet [as 别名]
# 或者: from jedi.evaluate.base_context.ContextSet import from_sets [as 别名]
def dict_values(self):
return ContextSet.from_sets(
self._defining_context.eval_node(v)
for k, v in self._items()
)
示例12: infer
# 需要导入模块: from jedi.evaluate.base_context import ContextSet [as 别名]
# 或者: from jedi.evaluate.base_context.ContextSet import from_sets [as 别名]
def infer(self):
return ContextSet.from_sets(p.infer() for p in self._executed_params)
示例13: execute_function_slots
# 需要导入模块: from jedi.evaluate.base_context import ContextSet [as 别名]
# 或者: from jedi.evaluate.base_context.ContextSet import from_sets [as 别名]
def execute_function_slots(self, names, *evaluated_args):
return ContextSet.from_sets(
name.execute_evaluated(*evaluated_args)
for name in names
)
示例14: execute
# 需要导入模块: from jedi.evaluate.base_context import ContextSet [as 别名]
# 或者: from jedi.evaluate.base_context.ContextSet import from_sets [as 别名]
def execute(arguments):
return ContextSet.from_sets(name.execute(arguments) for name in names)
示例15: infer
# 需要导入模块: from jedi.evaluate.base_context import ContextSet [as 别名]
# 或者: from jedi.evaluate.base_context.ContextSet import from_sets [as 别名]
def infer(self):
return ContextSet.from_sets(l.infer() for l in self.data)