_id stringlengths 2 7 | title stringlengths 1 88 | partition stringclasses 3
values | text stringlengths 31 13.1k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q30900 | TreeRebuilder.visit_compare | train | def visit_compare(self, node, parent):
"""visit a Compare node by returning a fresh instance of it"""
newnode = nodes.Compare(node.lineno, node.col_offset, parent)
newnode.postinit(
self.visit(node.left, newnode),
[
| python | {
"resource": ""
} |
q30901 | TreeRebuilder.visit_comprehension | train | def visit_comprehension(self, node, parent):
"""visit a Comprehension node by returning a fresh instance of it"""
newnode = nodes.Comprehension(parent)
newnode.postinit(
self.visit(node.target, newnode),
self.visit(node.iter, newnode),
| python | {
"resource": ""
} |
q30902 | TreeRebuilder.visit_decorators | train | def visit_decorators(self, node, parent):
"""visit a Decorators node by returning a fresh instance of it"""
# /!\ node is actually a _ast.FunctionDef node while
# parent is an astroid.nodes.FunctionDef node
| python | {
"resource": ""
} |
q30903 | TreeRebuilder.visit_delete | train | def visit_delete(self, node, parent):
"""visit a Delete node by returning a fresh instance of it"""
| python | {
"resource": ""
} |
q30904 | TreeRebuilder.visit_dict | train | def visit_dict(self, node, parent):
"""visit a Dict node by returning a fresh instance of it"""
newnode = nodes.Dict(node.lineno, node.col_offset, parent)
| python | {
"resource": ""
} |
q30905 | TreeRebuilder.visit_dictcomp | train | def visit_dictcomp(self, node, parent):
"""visit a DictComp node by returning a fresh instance of it"""
newnode = nodes.DictComp(node.lineno, node.col_offset, parent)
newnode.postinit(
self.visit(node.key, newnode),
| python | {
"resource": ""
} |
q30906 | TreeRebuilder.visit_expr | train | def visit_expr(self, node, parent):
"""visit a Expr node by returning a fresh instance of it"""
newnode = nodes.Expr(node.lineno, node.col_offset, parent)
| python | {
"resource": ""
} |
q30907 | TreeRebuilder.visit_ellipsis | train | def visit_ellipsis(self, node, parent):
"""visit an Ellipsis node by returning a fresh instance of it"""
return nodes.Ellipsis(
| python | {
"resource": ""
} |
q30908 | TreeRebuilder.visit_emptynode | train | def visit_emptynode(self, node, parent):
"""visit an EmptyNode node by returning a fresh instance of it"""
return nodes.EmptyNode(
| python | {
"resource": ""
} |
q30909 | TreeRebuilder.visit_exec | train | def visit_exec(self, node, parent):
"""visit an Exec node by returning a fresh instance of it"""
newnode = nodes.Exec(node.lineno, node.col_offset, parent)
newnode.postinit(
self.visit(node.body, newnode),
| python | {
"resource": ""
} |
q30910 | TreeRebuilder.visit_extslice | train | def visit_extslice(self, node, parent):
"""visit an ExtSlice node by returning a fresh instance of it"""
newnode = nodes.ExtSlice(parent=parent)
| python | {
"resource": ""
} |
q30911 | TreeRebuilder._visit_for | train | def _visit_for(self, cls, node, parent):
"""visit a For node by returning a fresh instance of it"""
newnode = cls(node.lineno, node.col_offset, parent)
type_annotation = self.check_type_comment(node)
newnode.postinit(
target=self.visit(node.target, newnode),
iter=... | python | {
"resource": ""
} |
q30912 | TreeRebuilder.visit_importfrom | train | def visit_importfrom(self, node, parent):
"""visit an ImportFrom node by returning a fresh instance of it"""
names = [(alias.name, alias.asname) for alias in node.names]
newnode = nodes.ImportFrom(
| python | {
"resource": ""
} |
q30913 | TreeRebuilder._visit_functiondef | train | def _visit_functiondef(self, cls, node, parent):
"""visit an FunctionDef node to become astroid"""
self._global_names.append({})
node, doc = self._get_doc(node)
newnode = cls(node.name, doc, node.lineno, node.col_offset, parent)
if node.decorator_list:
decorators = se... | python | {
"resource": ""
} |
q30914 | TreeRebuilder.visit_generatorexp | train | def visit_generatorexp(self, node, parent):
"""visit a GeneratorExp node by returning a fresh instance of it"""
newnode = nodes.GeneratorExp(node.lineno, node.col_offset, parent)
newnode.postinit(
| python | {
"resource": ""
} |
q30915 | TreeRebuilder.visit_attribute | train | def visit_attribute(self, node, parent):
"""visit an Attribute node by returning a fresh instance of it"""
context = self._get_context(node)
if context == astroid.Del:
# FIXME : maybe we should reintroduce and visit_delattr ?
# for instance, deactivating assign_ctx
... | python | {
"resource": ""
} |
q30916 | TreeRebuilder.visit_global | train | def visit_global(self, node, parent):
"""visit a Global node to become astroid"""
newnode = nodes.Global(
node.names,
getattr(node, "lineno", None),
getattr(node, "col_offset", None),
parent,
| python | {
"resource": ""
} |
q30917 | TreeRebuilder.visit_if | train | def visit_if(self, node, parent):
"""visit an If node by returning a fresh instance of it"""
newnode = nodes.If(node.lineno, node.col_offset, parent)
newnode.postinit(
self.visit(node.test, newnode),
[self.visit(child, | python | {
"resource": ""
} |
q30918 | TreeRebuilder.visit_ifexp | train | def visit_ifexp(self, node, parent):
"""visit a IfExp node by returning a fresh instance of it"""
newnode = nodes.IfExp(node.lineno, node.col_offset, parent)
newnode.postinit(
self.visit(node.test, newnode),
| python | {
"resource": ""
} |
q30919 | TreeRebuilder.visit_import | train | def visit_import(self, node, parent):
"""visit a Import node by returning a fresh instance of it"""
names = [(alias.name, alias.asname) for alias in node.names]
newnode = nodes.Import(
names,
| python | {
"resource": ""
} |
q30920 | TreeRebuilder.visit_index | train | def visit_index(self, node, parent):
"""visit a Index node by returning a fresh instance of it"""
newnode = nodes.Index(parent=parent)
| python | {
"resource": ""
} |
q30921 | TreeRebuilder.visit_keyword | train | def visit_keyword(self, node, parent):
"""visit a Keyword node by returning a fresh instance of it"""
newnode = nodes.Keyword(node.arg, parent=parent)
| python | {
"resource": ""
} |
q30922 | TreeRebuilder.visit_lambda | train | def visit_lambda(self, node, parent):
"""visit a Lambda node by returning a fresh instance of it"""
newnode = nodes.Lambda(node.lineno, node.col_offset, parent)
| python | {
"resource": ""
} |
q30923 | TreeRebuilder.visit_list | train | def visit_list(self, node, parent):
"""visit a List node by returning a fresh instance of it"""
context = self._get_context(node)
newnode = nodes.List(
| python | {
"resource": ""
} |
q30924 | TreeRebuilder.visit_listcomp | train | def visit_listcomp(self, node, parent):
"""visit a ListComp node by returning a fresh instance of it"""
newnode = nodes.ListComp(node.lineno, node.col_offset, parent)
newnode.postinit(
| python | {
"resource": ""
} |
q30925 | TreeRebuilder.visit_name | train | def visit_name(self, node, parent):
"""visit a Name node by returning a fresh instance of it"""
context = self._get_context(node)
# True and False can be assigned to something in py2x, so we have to
# check first the context.
if context == astroid.Del:
newnode = nodes... | python | {
"resource": ""
} |
q30926 | TreeRebuilder.visit_constant | train | def visit_constant(self, node, parent):
"""visit a Constant node by returning a fresh instance of Const"""
return nodes.Const(
node.value,
getattr(node, | python | {
"resource": ""
} |
q30927 | TreeRebuilder.visit_num | train | def visit_num(self, node, parent):
"""visit a Num node by returning a fresh instance of Const"""
| python | {
"resource": ""
} |
q30928 | TreeRebuilder.visit_pass | train | def visit_pass(self, node, parent):
"""visit a Pass node by returning a fresh instance of it"""
| python | {
"resource": ""
} |
q30929 | TreeRebuilder.visit_print | train | def visit_print(self, node, parent):
"""visit a Print node by returning a fresh instance of it"""
newnode = nodes.Print(node.nl, node.lineno, node.col_offset, parent)
newnode.postinit(
| python | {
"resource": ""
} |
q30930 | TreeRebuilder.visit_raise | train | def visit_raise(self, node, parent):
"""visit a Raise node by returning a fresh instance of it"""
newnode = nodes.Raise(node.lineno, node.col_offset, parent)
# pylint: disable=too-many-function-args
newnode.postinit(
_visit_or_none(node, "type", self, newnode),
| python | {
"resource": ""
} |
q30931 | TreeRebuilder.visit_return | train | def visit_return(self, node, parent):
"""visit a Return node by returning a fresh instance of it"""
newnode = | python | {
"resource": ""
} |
q30932 | TreeRebuilder.visit_set | train | def visit_set(self, node, parent):
"""visit a Set node by returning a fresh instance of it"""
| python | {
"resource": ""
} |
q30933 | TreeRebuilder.visit_setcomp | train | def visit_setcomp(self, node, parent):
"""visit a SetComp node by returning a fresh instance of it"""
newnode = nodes.SetComp(node.lineno, node.col_offset, parent)
newnode.postinit(
| python | {
"resource": ""
} |
q30934 | TreeRebuilder.visit_slice | train | def visit_slice(self, node, parent):
"""visit a Slice node by returning a fresh instance of it"""
newnode = nodes.Slice(parent=parent)
newnode.postinit(
_visit_or_none(node, "lower", self, newnode),
_visit_or_none(node, | python | {
"resource": ""
} |
q30935 | TreeRebuilder.visit_subscript | train | def visit_subscript(self, node, parent):
"""visit a Subscript node by returning a fresh instance of it"""
context = self._get_context(node)
newnode = nodes.Subscript( | python | {
"resource": ""
} |
q30936 | TreeRebuilder.visit_tryexcept | train | def visit_tryexcept(self, node, parent):
"""visit a TryExcept node by returning a fresh instance of it"""
newnode = nodes.TryExcept(node.lineno, node.col_offset, parent)
newnode.postinit(
[self.visit(child, newnode) for child in node.body],
| python | {
"resource": ""
} |
q30937 | TreeRebuilder.visit_tryfinally | train | def visit_tryfinally(self, node, parent):
"""visit a TryFinally node by returning a fresh instance of it"""
newnode = nodes.TryFinally(node.lineno, node.col_offset, parent)
newnode.postinit(
| python | {
"resource": ""
} |
q30938 | TreeRebuilder.visit_tuple | train | def visit_tuple(self, node, parent):
"""visit a Tuple node by returning a fresh instance of it"""
context = self._get_context(node)
newnode = nodes.Tuple(
| python | {
"resource": ""
} |
q30939 | TreeRebuilder.visit_unaryop | train | def visit_unaryop(self, node, parent):
"""visit a UnaryOp node by returning a fresh instance of it"""
newnode = nodes.UnaryOp(
self._unary_op_classes[node.op.__class__],
node.lineno,
node.col_offset, | python | {
"resource": ""
} |
q30940 | TreeRebuilder.visit_while | train | def visit_while(self, node, parent):
"""visit a While node by returning a fresh instance of it"""
newnode = nodes.While(node.lineno, node.col_offset, parent)
newnode.postinit(
self.visit(node.test, newnode),
| python | {
"resource": ""
} |
q30941 | TreeRebuilder.visit_yield | train | def visit_yield(self, node, parent):
"""visit a Yield node by returning a fresh instance of it"""
newnode = | python | {
"resource": ""
} |
q30942 | TreeRebuilder3.visit_arg | train | def visit_arg(self, node, parent):
"""visit an arg node by returning a fresh AssName instance"""
| python | {
"resource": ""
} |
q30943 | TreeRebuilder3.visit_excepthandler | train | def visit_excepthandler(self, node, parent):
"""visit an ExceptHandler node by returning a fresh instance of it"""
newnode = nodes.ExceptHandler(node.lineno, node.col_offset, parent)
if node.name:
| python | {
"resource": ""
} |
q30944 | TreeRebuilder3.visit_nonlocal | train | def visit_nonlocal(self, node, parent):
"""visit a Nonlocal node and return a new instance of it"""
| python | {
"resource": ""
} |
q30945 | TreeRebuilder3.visit_starred | train | def visit_starred(self, node, parent):
"""visit a Starred node and return a new instance of it"""
context = self._get_context(node)
newnode = nodes.Starred(
| python | {
"resource": ""
} |
q30946 | TreeRebuilder3.visit_annassign | train | def visit_annassign(self, node, parent):
"""visit an AnnAssign node by returning a fresh instance of it"""
newnode = nodes.AnnAssign(node.lineno, node.col_offset, parent)
annotation = _visit_or_none(node, "annotation", self, newnode)
newnode.postinit(
target=self.visit(node.t... | python | {
"resource": ""
} |
q30947 | AstroidManager.ast_from_module | train | def ast_from_module(self, module, modname=None):
"""given an imported module, return the astroid object"""
modname = modname or module.__name__
if modname in self.astroid_cache:
return self.astroid_cache[modname]
try:
| python | {
"resource": ""
} |
q30948 | AstroidManager.ast_from_class | train | def ast_from_class(self, klass, modname=None):
"""get astroid for the given class"""
if modname is None:
try:
modname = klass.__module__
except AttributeError as exc:
raise exceptions.AstroidBuildingError(
| python | {
"resource": ""
} |
q30949 | AstroidManager.infer_ast_from_something | train | def infer_ast_from_something(self, obj, context=None):
"""infer astroid for the given class"""
if hasattr(obj, "__class__") and not isinstance(obj, type):
klass = obj.__class__
else:
klass = obj
try:
modname = klass.__module__
except AttributeE... | python | {
"resource": ""
} |
q30950 | CallSite.from_call | train | def from_call(cls, call_node):
"""Get a CallSite object from the given Call node."""
| python | {
"resource": ""
} |
q30951 | _inference_tip_cached | train | def _inference_tip_cached(func, instance, args, kwargs, _cache={}):
"""Cache decorator used for inference tips"""
node = args[0]
try:
return iter(_cache[func, node]) | python | {
"resource": ""
} |
q30952 | inference_tip | train | def inference_tip(infer_function, raise_on_overwrite=False):
"""Given an instance specific inference function, return a function to be
given to MANAGER.register_transform to set this inference function.
:param bool raise_on_overwrite: Raise an `InferenceOverwriteError`
if the inference tip will ove... | python | {
"resource": ""
} |
q30953 | cached | train | def cached(func, instance, args, kwargs):
"""Simple decorator to cache result of method calls without args."""
cache = getattr(instance, "__cache", None)
if cache is None:
instance.__cache = cache = {}
try:
| python | {
"resource": ""
} |
q30954 | path_wrapper | train | def path_wrapper(func):
"""return the given infer function wrapped to handle the path
Used to stop inference if the node has already been looked
at for a given `InferenceContext` to prevent infinite recursion
"""
@functools.wraps(func)
def wrapped(node, context=None, _func=func, **kwargs):
... | python | {
"resource": ""
} |
q30955 | attach_dummy_node | train | def attach_dummy_node(node, name, runtime_object=_marker):
"""create a dummy node and register it in the locals of the given
node with the specified name
"""
| python | {
"resource": ""
} |
q30956 | attach_const_node | train | def attach_const_node(node, name, value):
"""create a Const node and register it in the locals of the given
node with the specified name
"""
| python | {
"resource": ""
} |
q30957 | attach_import_node | train | def attach_import_node(node, modname, membername):
"""create a ImportFrom node and register it in the locals of the given
node with the specified name
"""
| python | {
"resource": ""
} |
q30958 | build_module | train | def build_module(name, doc=None):
"""create and initialize an astroid Module node"""
node = nodes.Module(name, doc, pure_python=False) | python | {
"resource": ""
} |
q30959 | build_class | train | def build_class(name, basenames=(), doc=None):
"""create and initialize an astroid ClassDef node"""
node = nodes.ClassDef(name, doc)
for base in basenames:
basenode | python | {
"resource": ""
} |
q30960 | build_function | train | def build_function(name, args=None, defaults=None, doc=None):
"""create and initialize an astroid FunctionDef node"""
args, defaults = args or [], defaults or []
# first argument is now a list of decorators
func = nodes.FunctionDef(name, doc)
func.args = argsnode = nodes.Arguments()
argsnode.arg... | python | {
"resource": ""
} |
q30961 | register_arguments | train | def register_arguments(func, args=None):
"""add given arguments to local
args is a list that may contains nested lists
(i.e. def func(a, (b, c, d)): ...)
"""
if args is None:
args = func.args.args
if func.args.vararg:
func.set_local(func.args.vararg, func.args)
i... | python | {
"resource": ""
} |
q30962 | object_build_class | train | def object_build_class(node, member, localname):
"""create astroid for a living class object"""
| python | {
"resource": ""
} |
q30963 | object_build_function | train | def object_build_function(node, member, localname):
"""create astroid for a living function object"""
# pylint: disable=deprecated-method; completely removed in 2.0
args, varargs, varkw, defaults = inspect.getargspec(member)
if varargs is not None:
args.append(varargs)
if varkw is not None:
... | python | {
"resource": ""
} |
q30964 | object_build_methoddescriptor | train | def object_build_methoddescriptor(node, member, localname):
"""create astroid for a living method descriptor object"""
# FIXME get arguments ?
func = build_function(
getattr(member, "__name__", None) or localname, doc=member.__doc__
)
# set node's arguments | python | {
"resource": ""
} |
q30965 | _astroid_bootstrapping | train | def _astroid_bootstrapping():
"""astroid bootstrapping the builtins module"""
# this boot strapping is necessary since we need the Const nodes to
# inspect_build builtins, and then we can proxy Const
builder = InspectBuilder()
astroid_builtin = builder.inspect_build(builtins)
# pylint: disable=... | python | {
"resource": ""
} |
q30966 | InspectBuilder.imported_member | train | def imported_member(self, node, member, name):
"""verify this is not an imported class or handle it"""
# /!\ some classes like ExtensionClass doesn't have a __module__
# attribute ! Also, this may trigger an exception on badly built module
# (see http://www.logilab.org/ticket/57299 for i... | python | {
"resource": ""
} |
q30967 | parse | train | def parse(code, module_name="", path=None, apply_transforms=True):
"""Parses a source string in order to obtain an astroid AST from it
:param str code: The code for the module.
:param str module_name: The name for the module, if any
:param str path: The path for the module
:param bool apply_transfo... | python | {
"resource": ""
} |
q30968 | _extract_expressions | train | def _extract_expressions(node):
"""Find expressions in a call to _TRANSIENT_FUNCTION and extract them.
The function walks the AST recursively to search for expressions that
are wrapped into a call to _TRANSIENT_FUNCTION. If it finds such an
expression, it completely removes the function call node from ... | python | {
"resource": ""
} |
q30969 | _find_statement_by_line | train | def _find_statement_by_line(node, line):
"""Extracts the statement on a specific line from an AST.
If the line number of node matches line, it will be returned;
otherwise its children are iterated and the function is called
recursively.
:param node: An astroid node.
:type node: astroid.bases.N... | python | {
"resource": ""
} |
q30970 | extract_node | train | def extract_node(code, module_name=""):
"""Parses some Python code as a module and extracts a designated AST node.
Statements:
To extract one or more statement nodes, append #@ to the end of the line
Examples:
>>> def x():
>>> def y():
>>> return 1 #@
The return st... | python | {
"resource": ""
} |
q30971 | AstroidBuilder.module_build | train | def module_build(self, module, modname=None):
"""Build an astroid from a living module instance."""
node = None
path = getattr(module, "__file__", None)
if path is not None:
path_, ext = os.path.splitext(modutils._path_from_filename(path))
if ext in (".py", ".pyc"... | python | {
"resource": ""
} |
q30972 | AstroidBuilder.string_build | train | def string_build(self, data, modname="", path=None):
"""Build astroid from source code string."""
module = self._data_build(data, modname, path)
| python | {
"resource": ""
} |
q30973 | AstroidBuilder._post_build | train | def _post_build(self, module, encoding):
"""Handles encoding and delayed nodes after a module has been built"""
module.file_encoding = encoding
self._manager.cache_module(module)
# post tree building steps after we stored the module in the cache:
for from_node in module._import_f... | python | {
"resource": ""
} |
q30974 | AstroidBuilder._data_build | train | def _data_build(self, data, modname, path):
"""Build tree node from data and add some informations"""
try:
node = _parse(data + "\n")
except (TypeError, ValueError, SyntaxError) as exc:
raise exceptions.AstroidSyntaxError(
"Parsing Python code failed:\n{er... | python | {
"resource": ""
} |
q30975 | AstroidBuilder.add_from_names_to_locals | train | def add_from_names_to_locals(self, node):
"""Store imported names to the locals
Resort the locals if coming from a delayed node
"""
_key_func = lambda node: node.fromlineno
def sort_locals(my_list):
my_list.sort(key=_key_func)
for (name, asname) in node.nam... | python | {
"resource": ""
} |
q30976 | AstroidBuilder.delayed_assattr | train | def delayed_assattr(self, node):
"""Visit a AssAttr node
This adds name to locals and handle members definition.
"""
try:
frame = node.frame()
for inferred in node.expr.infer():
if inferred is util.Uninferable:
continue
... | python | {
"resource": ""
} |
q30977 | _resolve_looppart | train | def _resolve_looppart(parts, assign_path, context):
"""recursive function to resolve multiple assignments on loops"""
assign_path = assign_path[:]
index = assign_path.pop(0)
for part in parts:
if part is util.Uninferable:
continue
if not hasattr(part, "itered"):
c... | python | {
"resource": ""
} |
q30978 | _resolve_assignment_parts | train | def _resolve_assignment_parts(parts, assign_path, context):
"""recursive function to resolve multiple assignments"""
assign_path = assign_path[:]
index = assign_path.pop(0)
for part in parts:
assigned = None
if isinstance(part, nodes.Dict):
# A dictionary in an iterating cont... | python | {
"resource": ""
} |
q30979 | _infer_sequence_helper | train | def _infer_sequence_helper(node, context=None):
"""Infer all values based on _BaseContainer.elts"""
values = []
for elt in node.elts:
if isinstance(elt, nodes.Starred):
starred = helpers.safe_infer(elt.value, context)
| python | {
"resource": ""
} |
q30980 | _update_with_replacement | train | def _update_with_replacement(lhs_dict, rhs_dict):
"""Delete nodes that equate to duplicate keys
Since an astroid node doesn't 'equal' another node with the same value,
this function uses the as_string method to make sure duplicate keys
don't get through
Note that both the key and the value are ast... | python | {
"resource": ""
} |
q30981 | _infer_map | train | def _infer_map(node, context):
"""Infer all values based on Dict.items"""
values = {}
for name, value in node.items:
if isinstance(name, nodes.DictUnpack):
double_starred = helpers.safe_infer(value, context)
if not double_starred:
raise exceptions.InferenceErr... | python | {
"resource": ""
} |
q30982 | _higher_function_scope | train | def _higher_function_scope(node):
""" Search for the first function which encloses the given
scope. This can be used for looking up in that function's
scope, in case looking up in a lower scope for a particular
name fails.
:param node: A scope node.
:returns:
``None``, if no parent func... | python | {
"resource": ""
} |
q30983 | infer_call | train | def infer_call(self, context=None):
"""infer a Call node by trying to guess what the function returns"""
callcontext = contextmod.copy_context(context)
callcontext.callcontext = contextmod.CallContext(
args=self.args, keywords=self.keywords
)
callcontext.boundnode = None
if context is no... | python | {
"resource": ""
} |
q30984 | infer_attribute | train | def infer_attribute(self, context=None):
"""infer an Attribute node by using getattr on the associated object"""
for owner in self.expr.infer(context):
if owner is util.Uninferable:
yield owner
continue
if context and context.boundnode:
# This handles the sit... | python | {
"resource": ""
} |
q30985 | infer_subscript | train | def infer_subscript(self, context=None):
"""Inference for subscripts
We're understanding if the index is a Const
or a slice, passing the result of inference
to the value's `getitem` method, which should
handle each supported index type accordingly.
"""
found_one = False
for value in se... | python | {
"resource": ""
} |
q30986 | _invoke_binop_inference | train | def _invoke_binop_inference(instance, opnode, op, other, context, method_name):
"""Invoke binary operation inference on the given instance."""
methods = dunder_lookup.lookup(instance, method_name)
context = contextmod.bind_context_to_node(context, instance)
method = methods[0]
| python | {
"resource": ""
} |
q30987 | _aug_op | train | def _aug_op(instance, opnode, op, other, context, reverse=False):
"""Get an inference callable for an augmented binary operation."""
method_name = protocols.AUGMENTED_OP_METHOD[op]
return functools.partial(
_invoke_binop_inference,
| python | {
"resource": ""
} |
q30988 | _bin_op | train | def _bin_op(instance, opnode, op, other, context, reverse=False):
"""Get an inference callable for a normal binary operation.
If *reverse* is True, then the reflected method will be used instead.
"""
if reverse:
method_name = protocols.REFLECTED_BIN_OP_METHOD[op]
else:
method_name =... | python | {
"resource": ""
} |
q30989 | _get_binop_contexts | train | def _get_binop_contexts(context, left, right):
"""Get contexts for binary operations.
This will return two inference contexts, the first one
for x.__op__(y), the other one for y.__rop__(x), where
only the arguments are inversed.
"""
# The order is important, since the first one should be
# ... | python | {
"resource": ""
} |
q30990 | _get_binop_flow | train | def _get_binop_flow(
left, left_type, binary_opnode, right, right_type, context, reverse_context
):
"""Get the flow for binary operations.
The rules are a bit messy:
* if left and right have the same type, then only one
method will be called, left.__op__(right)
* if left and righ... | python | {
"resource": ""
} |
q30991 | _get_aug_flow | train | def _get_aug_flow(
left, left_type, aug_opnode, right, right_type, context, reverse_context
):
"""Get the flow for augmented binary operations.
The rules are a bit messy:
* if left and right have the same type, then left.__augop__(right)
is first tried and then left.__op__(right).
... | python | {
"resource": ""
} |
q30992 | _infer_binary_operation | train | def _infer_binary_operation(left, right, binary_opnode, context, flow_factory):
"""Infer a binary operation between a left operand and a right operand
This is used by both normal binary operations and augmented binary
operations, the only difference is the flow factory used.
"""
context, reverse_c... | python | {
"resource": ""
} |
q30993 | _infer_binop | train | def _infer_binop(self, context):
"""Binary operation inference logic."""
left = self.left
right = self.right
# we use two separate contexts for evaluating lhs and rhs because
# 1. evaluating lhs may leave some undesired entries in context.path
# which may not let us infer right value of rhs
... | python | {
"resource": ""
} |
q30994 | _infer_augassign | train | def _infer_augassign(self, context=None):
"""Inference logic for augmented binary operations."""
if context is None:
context = contextmod.InferenceContext()
rhs_context = context.clone()
lhs_iter = self.target.infer_lhs(context=context)
rhs_iter = self.value.infer(context=rhs_context)
... | python | {
"resource": ""
} |
q30995 | _nose_tools_functions | train | def _nose_tools_functions():
"""Get an iterator of names and bound methods."""
module = _BUILDER.string_build(
textwrap.dedent(
"""
import unittest
class Test(unittest.TestCase):
pass
a = Test()
"""
)
)
try:
case = next(module["a"].infer())
... | python | {
"resource": ""
} |
q30996 | _nose_tools_trivial_transform | train | def _nose_tools_trivial_transform():
"""Custom transform for the nose.tools module."""
stub = _BUILDER.string_build("""__all__ = []""")
all_entries = ["ok_", "eq_"]
for pep8_name, method in _nose_tools_functions():
all_entries.append(pep8_name)
stub[pep8_name] = method
# Update the... | python | {
"resource": ""
} |
q30997 | _looks_like_numpy_function | train | def _looks_like_numpy_function(func_name, numpy_module_name, node):
"""
Return True if the current node correspond to the function inside
the numpy module in parameters
:param node: the current node
:type node: FunctionDef
:param func_name: name of the function
:type func_name: str
:par... | python | {
"resource": ""
} |
q30998 | numpy_function_infer_call_result | train | def numpy_function_infer_call_result(node):
"""
A wrapper around infer_call_result method bounded to the node.
:param node: the node which infer_call_result should be filtered
:type node: FunctionDef
:return: a function that filter the results of the call to node.infer_call_result
:rtype: funct... | python | {
"resource": ""
} |
q30999 | unpack_infer | train | def unpack_infer(stmt, context=None):
"""recursively generate nodes inferred by the given statement.
If the inferred value is a list or a tuple, recurse on the elements
"""
if isinstance(stmt, (List, Tuple)):
for elt in stmt.elts:
if elt is util.Uninferable:
yield elt... | python | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.