id int32 0 252k | repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 51 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 |
|---|---|---|---|---|---|---|---|---|---|---|---|
227,100 | PyCQA/astroid | astroid/bases.py | BaseInstance._wrap_attr | def _wrap_attr(self, attrs, context=None):
"""wrap bound methods of attrs in a InstanceMethod proxies"""
for attr in attrs:
if isinstance(attr, UnboundMethod):
if _is_property(attr):
yield from attr.infer_call_result(self, context)
else:
yield BoundMethod(attr, self)
elif hasattr(attr, "name") and attr.name == "<lambda>":
if attr.args.args and attr.args.args[0].name == "self":
yield BoundMethod(attr, self)
continue
yield attr
else:
yield attr | python | def _wrap_attr(self, attrs, context=None):
for attr in attrs:
if isinstance(attr, UnboundMethod):
if _is_property(attr):
yield from attr.infer_call_result(self, context)
else:
yield BoundMethod(attr, self)
elif hasattr(attr, "name") and attr.name == "<lambda>":
if attr.args.args and attr.args.args[0].name == "self":
yield BoundMethod(attr, self)
continue
yield attr
else:
yield attr | [
"def",
"_wrap_attr",
"(",
"self",
",",
"attrs",
",",
"context",
"=",
"None",
")",
":",
"for",
"attr",
"in",
"attrs",
":",
"if",
"isinstance",
"(",
"attr",
",",
"UnboundMethod",
")",
":",
"if",
"_is_property",
"(",
"attr",
")",
":",
"yield",
"from",
"... | wrap bound methods of attrs in a InstanceMethod proxies | [
"wrap",
"bound",
"methods",
"of",
"attrs",
"in",
"a",
"InstanceMethod",
"proxies"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/bases.py#L237-L251 |
227,101 | PyCQA/astroid | astroid/bases.py | BaseInstance.infer_call_result | def infer_call_result(self, caller, context=None):
"""infer what a class instance is returning when called"""
context = contextmod.bind_context_to_node(context, self)
inferred = False
for node in self._proxied.igetattr("__call__", context):
if node is util.Uninferable or not node.callable():
continue
for res in node.infer_call_result(caller, context):
inferred = True
yield res
if not inferred:
raise exceptions.InferenceError(node=self, caller=caller, context=context) | python | def infer_call_result(self, caller, context=None):
context = contextmod.bind_context_to_node(context, self)
inferred = False
for node in self._proxied.igetattr("__call__", context):
if node is util.Uninferable or not node.callable():
continue
for res in node.infer_call_result(caller, context):
inferred = True
yield res
if not inferred:
raise exceptions.InferenceError(node=self, caller=caller, context=context) | [
"def",
"infer_call_result",
"(",
"self",
",",
"caller",
",",
"context",
"=",
"None",
")",
":",
"context",
"=",
"contextmod",
".",
"bind_context_to_node",
"(",
"context",
",",
"self",
")",
"inferred",
"=",
"False",
"for",
"node",
"in",
"self",
".",
"_proxie... | infer what a class instance is returning when called | [
"infer",
"what",
"a",
"class",
"instance",
"is",
"returning",
"when",
"called"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/bases.py#L253-L264 |
227,102 | PyCQA/astroid | astroid/bases.py | Instance.bool_value | def bool_value(self):
"""Infer the truth value for an Instance
The truth value of an instance is determined by these conditions:
* if it implements __bool__ on Python 3 or __nonzero__
on Python 2, then its bool value will be determined by
calling this special method and checking its result.
* when this method is not defined, __len__() is called, if it
is defined, and the object is considered true if its result is
nonzero. If a class defines neither __len__() nor __bool__(),
all its instances are considered true.
"""
context = contextmod.InferenceContext()
context.callcontext = contextmod.CallContext(args=[])
context.boundnode = self
try:
result = _infer_method_result_truth(self, BOOL_SPECIAL_METHOD, context)
except (exceptions.InferenceError, exceptions.AttributeInferenceError):
# Fallback to __len__.
try:
result = _infer_method_result_truth(self, "__len__", context)
except (exceptions.AttributeInferenceError, exceptions.InferenceError):
return True
return result | python | def bool_value(self):
context = contextmod.InferenceContext()
context.callcontext = contextmod.CallContext(args=[])
context.boundnode = self
try:
result = _infer_method_result_truth(self, BOOL_SPECIAL_METHOD, context)
except (exceptions.InferenceError, exceptions.AttributeInferenceError):
# Fallback to __len__.
try:
result = _infer_method_result_truth(self, "__len__", context)
except (exceptions.AttributeInferenceError, exceptions.InferenceError):
return True
return result | [
"def",
"bool_value",
"(",
"self",
")",
":",
"context",
"=",
"contextmod",
".",
"InferenceContext",
"(",
")",
"context",
".",
"callcontext",
"=",
"contextmod",
".",
"CallContext",
"(",
"args",
"=",
"[",
"]",
")",
"context",
".",
"boundnode",
"=",
"self",
... | Infer the truth value for an Instance
The truth value of an instance is determined by these conditions:
* if it implements __bool__ on Python 3 or __nonzero__
on Python 2, then its bool value will be determined by
calling this special method and checking its result.
* when this method is not defined, __len__() is called, if it
is defined, and the object is considered true if its result is
nonzero. If a class defines neither __len__() nor __bool__(),
all its instances are considered true. | [
"Infer",
"the",
"truth",
"value",
"for",
"an",
"Instance"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/bases.py#L296-L321 |
227,103 | PyCQA/astroid | astroid/interpreter/objectmodel.py | ObjectModel.attributes | def attributes(self):
"""Get the attributes which are exported by this object model."""
return [
obj[len(IMPL_PREFIX) :] for obj in dir(self) if obj.startswith(IMPL_PREFIX)
] | python | def attributes(self):
return [
obj[len(IMPL_PREFIX) :] for obj in dir(self) if obj.startswith(IMPL_PREFIX)
] | [
"def",
"attributes",
"(",
"self",
")",
":",
"return",
"[",
"obj",
"[",
"len",
"(",
"IMPL_PREFIX",
")",
":",
"]",
"for",
"obj",
"in",
"dir",
"(",
"self",
")",
"if",
"obj",
".",
"startswith",
"(",
"IMPL_PREFIX",
")",
"]"
] | Get the attributes which are exported by this object model. | [
"Get",
"the",
"attributes",
"which",
"are",
"exported",
"by",
"this",
"object",
"model",
"."
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/interpreter/objectmodel.py#L101-L105 |
227,104 | PyCQA/astroid | astroid/brain/brain_namedtuple_enum.py | infer_func_form | def infer_func_form(node, base_type, context=None, enum=False):
"""Specific inference function for namedtuple or Python 3 enum. """
# node is a Call node, class name as first argument and generated class
# attributes as second argument
# namedtuple or enums list of attributes can be a list of strings or a
# whitespace-separate string
try:
name, names = _find_func_form_arguments(node, context)
try:
attributes = names.value.replace(",", " ").split()
except AttributeError:
if not enum:
attributes = [
_infer_first(const, context).value for const in names.elts
]
else:
# Enums supports either iterator of (name, value) pairs
# or mappings.
if hasattr(names, "items") and isinstance(names.items, list):
attributes = [
_infer_first(const[0], context).value
for const in names.items
if isinstance(const[0], nodes.Const)
]
elif hasattr(names, "elts"):
# Enums can support either ["a", "b", "c"]
# or [("a", 1), ("b", 2), ...], but they can't
# be mixed.
if all(isinstance(const, nodes.Tuple) for const in names.elts):
attributes = [
_infer_first(const.elts[0], context).value
for const in names.elts
if isinstance(const, nodes.Tuple)
]
else:
attributes = [
_infer_first(const, context).value for const in names.elts
]
else:
raise AttributeError
if not attributes:
raise AttributeError
except (AttributeError, exceptions.InferenceError):
raise UseInferenceDefault()
# If we can't infer the name of the class, don't crash, up to this point
# we know it is a namedtuple anyway.
name = name or "Uninferable"
# we want to return a Class node instance with proper attributes set
class_node = nodes.ClassDef(name, "docstring")
class_node.parent = node.parent
# set base class=tuple
class_node.bases.append(base_type)
# XXX add __init__(*attributes) method
for attr in attributes:
fake_node = nodes.EmptyNode()
fake_node.parent = class_node
fake_node.attrname = attr
class_node.instance_attrs[attr] = [fake_node]
return class_node, name, attributes | python | def infer_func_form(node, base_type, context=None, enum=False):
# node is a Call node, class name as first argument and generated class
# attributes as second argument
# namedtuple or enums list of attributes can be a list of strings or a
# whitespace-separate string
try:
name, names = _find_func_form_arguments(node, context)
try:
attributes = names.value.replace(",", " ").split()
except AttributeError:
if not enum:
attributes = [
_infer_first(const, context).value for const in names.elts
]
else:
# Enums supports either iterator of (name, value) pairs
# or mappings.
if hasattr(names, "items") and isinstance(names.items, list):
attributes = [
_infer_first(const[0], context).value
for const in names.items
if isinstance(const[0], nodes.Const)
]
elif hasattr(names, "elts"):
# Enums can support either ["a", "b", "c"]
# or [("a", 1), ("b", 2), ...], but they can't
# be mixed.
if all(isinstance(const, nodes.Tuple) for const in names.elts):
attributes = [
_infer_first(const.elts[0], context).value
for const in names.elts
if isinstance(const, nodes.Tuple)
]
else:
attributes = [
_infer_first(const, context).value for const in names.elts
]
else:
raise AttributeError
if not attributes:
raise AttributeError
except (AttributeError, exceptions.InferenceError):
raise UseInferenceDefault()
# If we can't infer the name of the class, don't crash, up to this point
# we know it is a namedtuple anyway.
name = name or "Uninferable"
# we want to return a Class node instance with proper attributes set
class_node = nodes.ClassDef(name, "docstring")
class_node.parent = node.parent
# set base class=tuple
class_node.bases.append(base_type)
# XXX add __init__(*attributes) method
for attr in attributes:
fake_node = nodes.EmptyNode()
fake_node.parent = class_node
fake_node.attrname = attr
class_node.instance_attrs[attr] = [fake_node]
return class_node, name, attributes | [
"def",
"infer_func_form",
"(",
"node",
",",
"base_type",
",",
"context",
"=",
"None",
",",
"enum",
"=",
"False",
")",
":",
"# node is a Call node, class name as first argument and generated class",
"# attributes as second argument",
"# namedtuple or enums list of attributes can b... | Specific inference function for namedtuple or Python 3 enum. | [
"Specific",
"inference",
"function",
"for",
"namedtuple",
"or",
"Python",
"3",
"enum",
"."
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/brain/brain_namedtuple_enum.py#L78-L138 |
227,105 | PyCQA/astroid | astroid/brain/brain_namedtuple_enum.py | infer_enum | def infer_enum(node, context=None):
""" Specific inference function for enum Call node. """
enum_meta = extract_node(
"""
class EnumMeta(object):
'docstring'
def __call__(self, node):
class EnumAttribute(object):
name = ''
value = 0
return EnumAttribute()
def __iter__(self):
class EnumAttribute(object):
name = ''
value = 0
return [EnumAttribute()]
def __reversed__(self):
class EnumAttribute(object):
name = ''
value = 0
return (EnumAttribute, )
def __next__(self):
return next(iter(self))
def __getitem__(self, attr):
class Value(object):
@property
def name(self):
return ''
@property
def value(self):
return attr
return Value()
__members__ = ['']
"""
)
class_node = infer_func_form(node, enum_meta, context=context, enum=True)[0]
return iter([class_node.instantiate_class()]) | python | def infer_enum(node, context=None):
enum_meta = extract_node(
"""
class EnumMeta(object):
'docstring'
def __call__(self, node):
class EnumAttribute(object):
name = ''
value = 0
return EnumAttribute()
def __iter__(self):
class EnumAttribute(object):
name = ''
value = 0
return [EnumAttribute()]
def __reversed__(self):
class EnumAttribute(object):
name = ''
value = 0
return (EnumAttribute, )
def __next__(self):
return next(iter(self))
def __getitem__(self, attr):
class Value(object):
@property
def name(self):
return ''
@property
def value(self):
return attr
return Value()
__members__ = ['']
"""
)
class_node = infer_func_form(node, enum_meta, context=context, enum=True)[0]
return iter([class_node.instantiate_class()]) | [
"def",
"infer_enum",
"(",
"node",
",",
"context",
"=",
"None",
")",
":",
"enum_meta",
"=",
"extract_node",
"(",
"\"\"\"\n class EnumMeta(object):\n 'docstring'\n def __call__(self, node):\n class EnumAttribute(object):\n name = ''\n ... | Specific inference function for enum Call node. | [
"Specific",
"inference",
"function",
"for",
"enum",
"Call",
"node",
"."
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/brain/brain_namedtuple_enum.py#L239-L276 |
227,106 | PyCQA/astroid | astroid/brain/brain_namedtuple_enum.py | infer_typing_namedtuple_class | def infer_typing_namedtuple_class(class_node, context=None):
"""Infer a subclass of typing.NamedTuple"""
# Check if it has the corresponding bases
annassigns_fields = [
annassign.target.name
for annassign in class_node.body
if isinstance(annassign, nodes.AnnAssign)
]
code = dedent(
"""
from collections import namedtuple
namedtuple({typename!r}, {fields!r})
"""
).format(typename=class_node.name, fields=",".join(annassigns_fields))
node = extract_node(code)
generated_class_node = next(infer_named_tuple(node, context))
for method in class_node.mymethods():
generated_class_node.locals[method.name] = [method]
return iter((generated_class_node,)) | python | def infer_typing_namedtuple_class(class_node, context=None):
# Check if it has the corresponding bases
annassigns_fields = [
annassign.target.name
for annassign in class_node.body
if isinstance(annassign, nodes.AnnAssign)
]
code = dedent(
"""
from collections import namedtuple
namedtuple({typename!r}, {fields!r})
"""
).format(typename=class_node.name, fields=",".join(annassigns_fields))
node = extract_node(code)
generated_class_node = next(infer_named_tuple(node, context))
for method in class_node.mymethods():
generated_class_node.locals[method.name] = [method]
return iter((generated_class_node,)) | [
"def",
"infer_typing_namedtuple_class",
"(",
"class_node",
",",
"context",
"=",
"None",
")",
":",
"# Check if it has the corresponding bases",
"annassigns_fields",
"=",
"[",
"annassign",
".",
"target",
".",
"name",
"for",
"annassign",
"in",
"class_node",
".",
"body",
... | Infer a subclass of typing.NamedTuple | [
"Infer",
"a",
"subclass",
"of",
"typing",
".",
"NamedTuple"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/brain/brain_namedtuple_enum.py#L366-L384 |
227,107 | PyCQA/astroid | astroid/rebuilder.py | _visit_or_none | def _visit_or_none(node, attr, visitor, parent, visit="visit", **kws):
"""If the given node has an attribute, visits the attribute, and
otherwise returns None.
"""
value = getattr(node, attr, None)
if value:
return getattr(visitor, visit)(value, parent, **kws)
return None | python | def _visit_or_none(node, attr, visitor, parent, visit="visit", **kws):
value = getattr(node, attr, None)
if value:
return getattr(visitor, visit)(value, parent, **kws)
return None | [
"def",
"_visit_or_none",
"(",
"node",
",",
"attr",
",",
"visitor",
",",
"parent",
",",
"visit",
"=",
"\"visit\"",
",",
"*",
"*",
"kws",
")",
":",
"value",
"=",
"getattr",
"(",
"node",
",",
"attr",
",",
"None",
")",
"if",
"value",
":",
"return",
"ge... | If the given node has an attribute, visits the attribute, and
otherwise returns None. | [
"If",
"the",
"given",
"node",
"has",
"an",
"attribute",
"visits",
"the",
"attribute",
"and",
"otherwise",
"returns",
"None",
"."
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/rebuilder.py#L97-L106 |
227,108 | PyCQA/astroid | astroid/rebuilder.py | TreeRebuilder.visit_module | def visit_module(self, node, modname, modpath, package):
"""visit a Module node by returning a fresh instance of it"""
node, doc = self._get_doc(node)
newnode = nodes.Module(
name=modname,
doc=doc,
file=modpath,
path=[modpath],
package=package,
parent=None,
)
newnode.postinit([self.visit(child, newnode) for child in node.body])
return newnode | python | def visit_module(self, node, modname, modpath, package):
node, doc = self._get_doc(node)
newnode = nodes.Module(
name=modname,
doc=doc,
file=modpath,
path=[modpath],
package=package,
parent=None,
)
newnode.postinit([self.visit(child, newnode) for child in node.body])
return newnode | [
"def",
"visit_module",
"(",
"self",
",",
"node",
",",
"modname",
",",
"modpath",
",",
"package",
")",
":",
"node",
",",
"doc",
"=",
"self",
".",
"_get_doc",
"(",
"node",
")",
"newnode",
"=",
"nodes",
".",
"Module",
"(",
"name",
"=",
"modname",
",",
... | visit a Module node by returning a fresh instance of it | [
"visit",
"a",
"Module",
"node",
"by",
"returning",
"a",
"fresh",
"instance",
"of",
"it"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/rebuilder.py#L147-L159 |
227,109 | PyCQA/astroid | astroid/rebuilder.py | TreeRebuilder._save_assignment | def _save_assignment(self, node, name=None):
"""save assignement situation since node.parent is not available yet"""
if self._global_names and node.name in self._global_names[-1]:
node.root().set_local(node.name, node)
else:
node.parent.set_local(node.name, node) | python | def _save_assignment(self, node, name=None):
if self._global_names and node.name in self._global_names[-1]:
node.root().set_local(node.name, node)
else:
node.parent.set_local(node.name, node) | [
"def",
"_save_assignment",
"(",
"self",
",",
"node",
",",
"name",
"=",
"None",
")",
":",
"if",
"self",
".",
"_global_names",
"and",
"node",
".",
"name",
"in",
"self",
".",
"_global_names",
"[",
"-",
"1",
"]",
":",
"node",
".",
"root",
"(",
")",
"."... | save assignement situation since node.parent is not available yet | [
"save",
"assignement",
"situation",
"since",
"node",
".",
"parent",
"is",
"not",
"available",
"yet"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/rebuilder.py#L172-L177 |
227,110 | PyCQA/astroid | astroid/rebuilder.py | TreeRebuilder.visit_arguments | def visit_arguments(self, node, parent):
"""visit an Arguments node by returning a fresh instance of it"""
vararg, kwarg = node.vararg, node.kwarg
if PY34:
newnode = nodes.Arguments(
vararg.arg if vararg else None, kwarg.arg if kwarg else None, parent
)
else:
newnode = nodes.Arguments(vararg, kwarg, parent)
args = [self.visit(child, newnode) for child in node.args]
defaults = [self.visit(child, newnode) for child in node.defaults]
varargannotation = None
kwargannotation = None
# change added in 82732 (7c5c678e4164), vararg and kwarg
# are instances of `_ast.arg`, not strings
if vararg:
if PY34:
if node.vararg.annotation:
varargannotation = self.visit(node.vararg.annotation, newnode)
vararg = vararg.arg
if kwarg:
if PY34:
if node.kwarg.annotation:
kwargannotation = self.visit(node.kwarg.annotation, newnode)
kwarg = kwarg.arg
if PY3:
kwonlyargs = [self.visit(child, newnode) for child in node.kwonlyargs]
kw_defaults = [
self.visit(child, newnode) if child else None
for child in node.kw_defaults
]
annotations = [
self.visit(arg.annotation, newnode) if arg.annotation else None
for arg in node.args
]
kwonlyargs_annotations = [
self.visit(arg.annotation, newnode) if arg.annotation else None
for arg in node.kwonlyargs
]
else:
kwonlyargs = []
kw_defaults = []
annotations = []
kwonlyargs_annotations = []
newnode.postinit(
args=args,
defaults=defaults,
kwonlyargs=kwonlyargs,
kw_defaults=kw_defaults,
annotations=annotations,
kwonlyargs_annotations=kwonlyargs_annotations,
varargannotation=varargannotation,
kwargannotation=kwargannotation,
)
# save argument names in locals:
if vararg:
newnode.parent.set_local(vararg, newnode)
if kwarg:
newnode.parent.set_local(kwarg, newnode)
return newnode | python | def visit_arguments(self, node, parent):
vararg, kwarg = node.vararg, node.kwarg
if PY34:
newnode = nodes.Arguments(
vararg.arg if vararg else None, kwarg.arg if kwarg else None, parent
)
else:
newnode = nodes.Arguments(vararg, kwarg, parent)
args = [self.visit(child, newnode) for child in node.args]
defaults = [self.visit(child, newnode) for child in node.defaults]
varargannotation = None
kwargannotation = None
# change added in 82732 (7c5c678e4164), vararg and kwarg
# are instances of `_ast.arg`, not strings
if vararg:
if PY34:
if node.vararg.annotation:
varargannotation = self.visit(node.vararg.annotation, newnode)
vararg = vararg.arg
if kwarg:
if PY34:
if node.kwarg.annotation:
kwargannotation = self.visit(node.kwarg.annotation, newnode)
kwarg = kwarg.arg
if PY3:
kwonlyargs = [self.visit(child, newnode) for child in node.kwonlyargs]
kw_defaults = [
self.visit(child, newnode) if child else None
for child in node.kw_defaults
]
annotations = [
self.visit(arg.annotation, newnode) if arg.annotation else None
for arg in node.args
]
kwonlyargs_annotations = [
self.visit(arg.annotation, newnode) if arg.annotation else None
for arg in node.kwonlyargs
]
else:
kwonlyargs = []
kw_defaults = []
annotations = []
kwonlyargs_annotations = []
newnode.postinit(
args=args,
defaults=defaults,
kwonlyargs=kwonlyargs,
kw_defaults=kw_defaults,
annotations=annotations,
kwonlyargs_annotations=kwonlyargs_annotations,
varargannotation=varargannotation,
kwargannotation=kwargannotation,
)
# save argument names in locals:
if vararg:
newnode.parent.set_local(vararg, newnode)
if kwarg:
newnode.parent.set_local(kwarg, newnode)
return newnode | [
"def",
"visit_arguments",
"(",
"self",
",",
"node",
",",
"parent",
")",
":",
"vararg",
",",
"kwarg",
"=",
"node",
".",
"vararg",
",",
"node",
".",
"kwarg",
"if",
"PY34",
":",
"newnode",
"=",
"nodes",
".",
"Arguments",
"(",
"vararg",
".",
"arg",
"if",... | visit an Arguments node by returning a fresh instance of it | [
"visit",
"an",
"Arguments",
"node",
"by",
"returning",
"a",
"fresh",
"instance",
"of",
"it"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/rebuilder.py#L179-L239 |
227,111 | PyCQA/astroid | astroid/rebuilder.py | TreeRebuilder.visit_assert | def visit_assert(self, node, parent):
"""visit a Assert node by returning a fresh instance of it"""
newnode = nodes.Assert(node.lineno, node.col_offset, parent)
if node.msg:
msg = self.visit(node.msg, newnode)
else:
msg = None
newnode.postinit(self.visit(node.test, newnode), msg)
return newnode | python | def visit_assert(self, node, parent):
newnode = nodes.Assert(node.lineno, node.col_offset, parent)
if node.msg:
msg = self.visit(node.msg, newnode)
else:
msg = None
newnode.postinit(self.visit(node.test, newnode), msg)
return newnode | [
"def",
"visit_assert",
"(",
"self",
",",
"node",
",",
"parent",
")",
":",
"newnode",
"=",
"nodes",
".",
"Assert",
"(",
"node",
".",
"lineno",
",",
"node",
".",
"col_offset",
",",
"parent",
")",
"if",
"node",
".",
"msg",
":",
"msg",
"=",
"self",
"."... | visit a Assert node by returning a fresh instance of it | [
"visit",
"a",
"Assert",
"node",
"by",
"returning",
"a",
"fresh",
"instance",
"of",
"it"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/rebuilder.py#L241-L249 |
227,112 | PyCQA/astroid | astroid/rebuilder.py | TreeRebuilder.visit_assign | def visit_assign(self, node, parent):
"""visit a Assign node by returning a fresh instance of it"""
type_annotation = self.check_type_comment(node)
newnode = nodes.Assign(node.lineno, node.col_offset, parent)
newnode.postinit(
targets=[self.visit(child, newnode) for child in node.targets],
value=self.visit(node.value, newnode),
type_annotation=type_annotation,
)
return newnode | python | def visit_assign(self, node, parent):
type_annotation = self.check_type_comment(node)
newnode = nodes.Assign(node.lineno, node.col_offset, parent)
newnode.postinit(
targets=[self.visit(child, newnode) for child in node.targets],
value=self.visit(node.value, newnode),
type_annotation=type_annotation,
)
return newnode | [
"def",
"visit_assign",
"(",
"self",
",",
"node",
",",
"parent",
")",
":",
"type_annotation",
"=",
"self",
".",
"check_type_comment",
"(",
"node",
")",
"newnode",
"=",
"nodes",
".",
"Assign",
"(",
"node",
".",
"lineno",
",",
"node",
".",
"col_offset",
","... | visit a Assign node by returning a fresh instance of it | [
"visit",
"a",
"Assign",
"node",
"by",
"returning",
"a",
"fresh",
"instance",
"of",
"it"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/rebuilder.py#L288-L297 |
227,113 | PyCQA/astroid | astroid/rebuilder.py | TreeRebuilder.visit_assignname | def visit_assignname(self, node, parent, node_name=None):
"""visit a node and return a AssignName node"""
newnode = nodes.AssignName(
node_name,
getattr(node, "lineno", None),
getattr(node, "col_offset", None),
parent,
)
self._save_assignment(newnode)
return newnode | python | def visit_assignname(self, node, parent, node_name=None):
newnode = nodes.AssignName(
node_name,
getattr(node, "lineno", None),
getattr(node, "col_offset", None),
parent,
)
self._save_assignment(newnode)
return newnode | [
"def",
"visit_assignname",
"(",
"self",
",",
"node",
",",
"parent",
",",
"node_name",
"=",
"None",
")",
":",
"newnode",
"=",
"nodes",
".",
"AssignName",
"(",
"node_name",
",",
"getattr",
"(",
"node",
",",
"\"lineno\"",
",",
"None",
")",
",",
"getattr",
... | visit a node and return a AssignName node | [
"visit",
"a",
"node",
"and",
"return",
"a",
"AssignName",
"node"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/rebuilder.py#L299-L308 |
227,114 | PyCQA/astroid | astroid/rebuilder.py | TreeRebuilder.visit_augassign | def visit_augassign(self, node, parent):
"""visit a AugAssign node by returning a fresh instance of it"""
newnode = nodes.AugAssign(
self._bin_op_classes[type(node.op)] + "=",
node.lineno,
node.col_offset,
parent,
)
newnode.postinit(
self.visit(node.target, newnode), self.visit(node.value, newnode)
)
return newnode | python | def visit_augassign(self, node, parent):
newnode = nodes.AugAssign(
self._bin_op_classes[type(node.op)] + "=",
node.lineno,
node.col_offset,
parent,
)
newnode.postinit(
self.visit(node.target, newnode), self.visit(node.value, newnode)
)
return newnode | [
"def",
"visit_augassign",
"(",
"self",
",",
"node",
",",
"parent",
")",
":",
"newnode",
"=",
"nodes",
".",
"AugAssign",
"(",
"self",
".",
"_bin_op_classes",
"[",
"type",
"(",
"node",
".",
"op",
")",
"]",
"+",
"\"=\"",
",",
"node",
".",
"lineno",
",",... | visit a AugAssign node by returning a fresh instance of it | [
"visit",
"a",
"AugAssign",
"node",
"by",
"returning",
"a",
"fresh",
"instance",
"of",
"it"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/rebuilder.py#L310-L321 |
227,115 | PyCQA/astroid | astroid/rebuilder.py | TreeRebuilder.visit_repr | def visit_repr(self, node, parent):
"""visit a Backquote node by returning a fresh instance of it"""
newnode = nodes.Repr(node.lineno, node.col_offset, parent)
newnode.postinit(self.visit(node.value, newnode))
return newnode | python | def visit_repr(self, node, parent):
newnode = nodes.Repr(node.lineno, node.col_offset, parent)
newnode.postinit(self.visit(node.value, newnode))
return newnode | [
"def",
"visit_repr",
"(",
"self",
",",
"node",
",",
"parent",
")",
":",
"newnode",
"=",
"nodes",
".",
"Repr",
"(",
"node",
".",
"lineno",
",",
"node",
".",
"col_offset",
",",
"parent",
")",
"newnode",
".",
"postinit",
"(",
"self",
".",
"visit",
"(",
... | visit a Backquote node by returning a fresh instance of it | [
"visit",
"a",
"Backquote",
"node",
"by",
"returning",
"a",
"fresh",
"instance",
"of",
"it"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/rebuilder.py#L323-L327 |
227,116 | PyCQA/astroid | astroid/rebuilder.py | TreeRebuilder.visit_binop | def visit_binop(self, node, parent):
"""visit a BinOp node by returning a fresh instance of it"""
newnode = nodes.BinOp(
self._bin_op_classes[type(node.op)], node.lineno, node.col_offset, parent
)
newnode.postinit(
self.visit(node.left, newnode), self.visit(node.right, newnode)
)
return newnode | python | def visit_binop(self, node, parent):
newnode = nodes.BinOp(
self._bin_op_classes[type(node.op)], node.lineno, node.col_offset, parent
)
newnode.postinit(
self.visit(node.left, newnode), self.visit(node.right, newnode)
)
return newnode | [
"def",
"visit_binop",
"(",
"self",
",",
"node",
",",
"parent",
")",
":",
"newnode",
"=",
"nodes",
".",
"BinOp",
"(",
"self",
".",
"_bin_op_classes",
"[",
"type",
"(",
"node",
".",
"op",
")",
"]",
",",
"node",
".",
"lineno",
",",
"node",
".",
"col_o... | visit a BinOp node by returning a fresh instance of it | [
"visit",
"a",
"BinOp",
"node",
"by",
"returning",
"a",
"fresh",
"instance",
"of",
"it"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/rebuilder.py#L329-L337 |
227,117 | PyCQA/astroid | astroid/rebuilder.py | TreeRebuilder.visit_boolop | def visit_boolop(self, node, parent):
"""visit a BoolOp node by returning a fresh instance of it"""
newnode = nodes.BoolOp(
self._bool_op_classes[type(node.op)], node.lineno, node.col_offset, parent
)
newnode.postinit([self.visit(child, newnode) for child in node.values])
return newnode | python | def visit_boolop(self, node, parent):
newnode = nodes.BoolOp(
self._bool_op_classes[type(node.op)], node.lineno, node.col_offset, parent
)
newnode.postinit([self.visit(child, newnode) for child in node.values])
return newnode | [
"def",
"visit_boolop",
"(",
"self",
",",
"node",
",",
"parent",
")",
":",
"newnode",
"=",
"nodes",
".",
"BoolOp",
"(",
"self",
".",
"_bool_op_classes",
"[",
"type",
"(",
"node",
".",
"op",
")",
"]",
",",
"node",
".",
"lineno",
",",
"node",
".",
"co... | visit a BoolOp node by returning a fresh instance of it | [
"visit",
"a",
"BoolOp",
"node",
"by",
"returning",
"a",
"fresh",
"instance",
"of",
"it"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/rebuilder.py#L339-L345 |
227,118 | PyCQA/astroid | astroid/rebuilder.py | TreeRebuilder.visit_break | def visit_break(self, node, parent):
"""visit a Break node by returning a fresh instance of it"""
return nodes.Break(
getattr(node, "lineno", None), getattr(node, "col_offset", None), parent
) | python | def visit_break(self, node, parent):
return nodes.Break(
getattr(node, "lineno", None), getattr(node, "col_offset", None), parent
) | [
"def",
"visit_break",
"(",
"self",
",",
"node",
",",
"parent",
")",
":",
"return",
"nodes",
".",
"Break",
"(",
"getattr",
"(",
"node",
",",
"\"lineno\"",
",",
"None",
")",
",",
"getattr",
"(",
"node",
",",
"\"col_offset\"",
",",
"None",
")",
",",
"pa... | visit a Break node by returning a fresh instance of it | [
"visit",
"a",
"Break",
"node",
"by",
"returning",
"a",
"fresh",
"instance",
"of",
"it"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/rebuilder.py#L347-L351 |
227,119 | PyCQA/astroid | astroid/rebuilder.py | TreeRebuilder.visit_call | def visit_call(self, node, parent):
"""visit a CallFunc node by returning a fresh instance of it"""
newnode = nodes.Call(node.lineno, node.col_offset, parent)
starargs = _visit_or_none(node, "starargs", self, newnode)
kwargs = _visit_or_none(node, "kwargs", self, newnode)
args = [self.visit(child, newnode) for child in node.args]
if node.keywords:
keywords = [self.visit(child, newnode) for child in node.keywords]
else:
keywords = None
if starargs:
new_starargs = nodes.Starred(
col_offset=starargs.col_offset,
lineno=starargs.lineno,
parent=starargs.parent,
)
new_starargs.postinit(value=starargs)
args.append(new_starargs)
if kwargs:
new_kwargs = nodes.Keyword(
arg=None,
col_offset=kwargs.col_offset,
lineno=kwargs.lineno,
parent=kwargs.parent,
)
new_kwargs.postinit(value=kwargs)
if keywords:
keywords.append(new_kwargs)
else:
keywords = [new_kwargs]
newnode.postinit(self.visit(node.func, newnode), args, keywords)
return newnode | python | def visit_call(self, node, parent):
newnode = nodes.Call(node.lineno, node.col_offset, parent)
starargs = _visit_or_none(node, "starargs", self, newnode)
kwargs = _visit_or_none(node, "kwargs", self, newnode)
args = [self.visit(child, newnode) for child in node.args]
if node.keywords:
keywords = [self.visit(child, newnode) for child in node.keywords]
else:
keywords = None
if starargs:
new_starargs = nodes.Starred(
col_offset=starargs.col_offset,
lineno=starargs.lineno,
parent=starargs.parent,
)
new_starargs.postinit(value=starargs)
args.append(new_starargs)
if kwargs:
new_kwargs = nodes.Keyword(
arg=None,
col_offset=kwargs.col_offset,
lineno=kwargs.lineno,
parent=kwargs.parent,
)
new_kwargs.postinit(value=kwargs)
if keywords:
keywords.append(new_kwargs)
else:
keywords = [new_kwargs]
newnode.postinit(self.visit(node.func, newnode), args, keywords)
return newnode | [
"def",
"visit_call",
"(",
"self",
",",
"node",
",",
"parent",
")",
":",
"newnode",
"=",
"nodes",
".",
"Call",
"(",
"node",
".",
"lineno",
",",
"node",
".",
"col_offset",
",",
"parent",
")",
"starargs",
"=",
"_visit_or_none",
"(",
"node",
",",
"\"starar... | visit a CallFunc node by returning a fresh instance of it | [
"visit",
"a",
"CallFunc",
"node",
"by",
"returning",
"a",
"fresh",
"instance",
"of",
"it"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/rebuilder.py#L353-L386 |
227,120 | PyCQA/astroid | astroid/rebuilder.py | TreeRebuilder.visit_classdef | def visit_classdef(self, node, parent, newstyle=None):
"""visit a ClassDef node to become astroid"""
node, doc = self._get_doc(node)
newnode = nodes.ClassDef(node.name, doc, node.lineno, node.col_offset, parent)
metaclass = None
if PY3:
for keyword in node.keywords:
if keyword.arg == "metaclass":
metaclass = self.visit(keyword, newnode).value
break
if node.decorator_list:
decorators = self.visit_decorators(node, newnode)
else:
decorators = None
newnode.postinit(
[self.visit(child, newnode) for child in node.bases],
[self.visit(child, newnode) for child in node.body],
decorators,
newstyle,
metaclass,
[
self.visit(kwd, newnode)
for kwd in node.keywords
if kwd.arg != "metaclass"
]
if PY3
else [],
)
return newnode | python | def visit_classdef(self, node, parent, newstyle=None):
node, doc = self._get_doc(node)
newnode = nodes.ClassDef(node.name, doc, node.lineno, node.col_offset, parent)
metaclass = None
if PY3:
for keyword in node.keywords:
if keyword.arg == "metaclass":
metaclass = self.visit(keyword, newnode).value
break
if node.decorator_list:
decorators = self.visit_decorators(node, newnode)
else:
decorators = None
newnode.postinit(
[self.visit(child, newnode) for child in node.bases],
[self.visit(child, newnode) for child in node.body],
decorators,
newstyle,
metaclass,
[
self.visit(kwd, newnode)
for kwd in node.keywords
if kwd.arg != "metaclass"
]
if PY3
else [],
)
return newnode | [
"def",
"visit_classdef",
"(",
"self",
",",
"node",
",",
"parent",
",",
"newstyle",
"=",
"None",
")",
":",
"node",
",",
"doc",
"=",
"self",
".",
"_get_doc",
"(",
"node",
")",
"newnode",
"=",
"nodes",
".",
"ClassDef",
"(",
"node",
".",
"name",
",",
"... | visit a ClassDef node to become astroid | [
"visit",
"a",
"ClassDef",
"node",
"to",
"become",
"astroid"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/rebuilder.py#L388-L416 |
227,121 | PyCQA/astroid | astroid/rebuilder.py | TreeRebuilder.visit_const | def visit_const(self, node, parent):
"""visit a Const node by returning a fresh instance of it"""
return nodes.Const(
node.value,
getattr(node, "lineno", None),
getattr(node, "col_offset", None),
parent,
) | python | def visit_const(self, node, parent):
return nodes.Const(
node.value,
getattr(node, "lineno", None),
getattr(node, "col_offset", None),
parent,
) | [
"def",
"visit_const",
"(",
"self",
",",
"node",
",",
"parent",
")",
":",
"return",
"nodes",
".",
"Const",
"(",
"node",
".",
"value",
",",
"getattr",
"(",
"node",
",",
"\"lineno\"",
",",
"None",
")",
",",
"getattr",
"(",
"node",
",",
"\"col_offset\"",
... | visit a Const node by returning a fresh instance of it | [
"visit",
"a",
"Const",
"node",
"by",
"returning",
"a",
"fresh",
"instance",
"of",
"it"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/rebuilder.py#L418-L425 |
227,122 | PyCQA/astroid | astroid/rebuilder.py | TreeRebuilder.visit_continue | def visit_continue(self, node, parent):
"""visit a Continue node by returning a fresh instance of it"""
return nodes.Continue(
getattr(node, "lineno", None), getattr(node, "col_offset", None), parent
) | python | def visit_continue(self, node, parent):
return nodes.Continue(
getattr(node, "lineno", None), getattr(node, "col_offset", None), parent
) | [
"def",
"visit_continue",
"(",
"self",
",",
"node",
",",
"parent",
")",
":",
"return",
"nodes",
".",
"Continue",
"(",
"getattr",
"(",
"node",
",",
"\"lineno\"",
",",
"None",
")",
",",
"getattr",
"(",
"node",
",",
"\"col_offset\"",
",",
"None",
")",
",",... | visit a Continue node by returning a fresh instance of it | [
"visit",
"a",
"Continue",
"node",
"by",
"returning",
"a",
"fresh",
"instance",
"of",
"it"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/rebuilder.py#L427-L431 |
227,123 | PyCQA/astroid | astroid/rebuilder.py | TreeRebuilder.visit_compare | 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),
[
(self._cmp_op_classes[op.__class__], self.visit(expr, newnode))
for (op, expr) in zip(node.ops, node.comparators)
],
)
return newnode | python | def visit_compare(self, node, parent):
newnode = nodes.Compare(node.lineno, node.col_offset, parent)
newnode.postinit(
self.visit(node.left, newnode),
[
(self._cmp_op_classes[op.__class__], self.visit(expr, newnode))
for (op, expr) in zip(node.ops, node.comparators)
],
)
return newnode | [
"def",
"visit_compare",
"(",
"self",
",",
"node",
",",
"parent",
")",
":",
"newnode",
"=",
"nodes",
".",
"Compare",
"(",
"node",
".",
"lineno",
",",
"node",
".",
"col_offset",
",",
"parent",
")",
"newnode",
".",
"postinit",
"(",
"self",
".",
"visit",
... | visit a Compare node by returning a fresh instance of it | [
"visit",
"a",
"Compare",
"node",
"by",
"returning",
"a",
"fresh",
"instance",
"of",
"it"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/rebuilder.py#L433-L443 |
227,124 | PyCQA/astroid | astroid/rebuilder.py | TreeRebuilder.visit_comprehension | 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),
[self.visit(child, newnode) for child in node.ifs],
getattr(node, "is_async", None),
)
return newnode | python | def visit_comprehension(self, node, parent):
newnode = nodes.Comprehension(parent)
newnode.postinit(
self.visit(node.target, newnode),
self.visit(node.iter, newnode),
[self.visit(child, newnode) for child in node.ifs],
getattr(node, "is_async", None),
)
return newnode | [
"def",
"visit_comprehension",
"(",
"self",
",",
"node",
",",
"parent",
")",
":",
"newnode",
"=",
"nodes",
".",
"Comprehension",
"(",
"parent",
")",
"newnode",
".",
"postinit",
"(",
"self",
".",
"visit",
"(",
"node",
".",
"target",
",",
"newnode",
")",
... | visit a Comprehension node by returning a fresh instance of it | [
"visit",
"a",
"Comprehension",
"node",
"by",
"returning",
"a",
"fresh",
"instance",
"of",
"it"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/rebuilder.py#L445-L454 |
227,125 | PyCQA/astroid | astroid/rebuilder.py | TreeRebuilder.visit_decorators | 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
newnode = nodes.Decorators(node.lineno, node.col_offset, parent)
newnode.postinit([self.visit(child, newnode) for child in node.decorator_list])
return newnode | python | def visit_decorators(self, node, parent):
# /!\ node is actually a _ast.FunctionDef node while
# parent is an astroid.nodes.FunctionDef node
newnode = nodes.Decorators(node.lineno, node.col_offset, parent)
newnode.postinit([self.visit(child, newnode) for child in node.decorator_list])
return newnode | [
"def",
"visit_decorators",
"(",
"self",
",",
"node",
",",
"parent",
")",
":",
"# /!\\ node is actually a _ast.FunctionDef node while",
"# parent is an astroid.nodes.FunctionDef node",
"newnode",
"=",
"nodes",
".",
"Decorators",
"(",
"node",
".",
"lineno",
",",
"node",
"... | visit a Decorators node by returning a fresh instance of it | [
"visit",
"a",
"Decorators",
"node",
"by",
"returning",
"a",
"fresh",
"instance",
"of",
"it"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/rebuilder.py#L456-L462 |
227,126 | PyCQA/astroid | astroid/rebuilder.py | TreeRebuilder.visit_delete | def visit_delete(self, node, parent):
"""visit a Delete node by returning a fresh instance of it"""
newnode = nodes.Delete(node.lineno, node.col_offset, parent)
newnode.postinit([self.visit(child, newnode) for child in node.targets])
return newnode | python | def visit_delete(self, node, parent):
newnode = nodes.Delete(node.lineno, node.col_offset, parent)
newnode.postinit([self.visit(child, newnode) for child in node.targets])
return newnode | [
"def",
"visit_delete",
"(",
"self",
",",
"node",
",",
"parent",
")",
":",
"newnode",
"=",
"nodes",
".",
"Delete",
"(",
"node",
".",
"lineno",
",",
"node",
".",
"col_offset",
",",
"parent",
")",
"newnode",
".",
"postinit",
"(",
"[",
"self",
".",
"visi... | visit a Delete node by returning a fresh instance of it | [
"visit",
"a",
"Delete",
"node",
"by",
"returning",
"a",
"fresh",
"instance",
"of",
"it"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/rebuilder.py#L464-L468 |
227,127 | PyCQA/astroid | astroid/rebuilder.py | TreeRebuilder.visit_dict | 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)
items = list(self._visit_dict_items(node, parent, newnode))
newnode.postinit(items)
return newnode | python | def visit_dict(self, node, parent):
newnode = nodes.Dict(node.lineno, node.col_offset, parent)
items = list(self._visit_dict_items(node, parent, newnode))
newnode.postinit(items)
return newnode | [
"def",
"visit_dict",
"(",
"self",
",",
"node",
",",
"parent",
")",
":",
"newnode",
"=",
"nodes",
".",
"Dict",
"(",
"node",
".",
"lineno",
",",
"node",
".",
"col_offset",
",",
"parent",
")",
"items",
"=",
"list",
"(",
"self",
".",
"_visit_dict_items",
... | visit a Dict node by returning a fresh instance of it | [
"visit",
"a",
"Dict",
"node",
"by",
"returning",
"a",
"fresh",
"instance",
"of",
"it"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/rebuilder.py#L482-L487 |
227,128 | PyCQA/astroid | astroid/rebuilder.py | TreeRebuilder.visit_dictcomp | 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),
self.visit(node.value, newnode),
[self.visit(child, newnode) for child in node.generators],
)
return newnode | python | def visit_dictcomp(self, node, parent):
newnode = nodes.DictComp(node.lineno, node.col_offset, parent)
newnode.postinit(
self.visit(node.key, newnode),
self.visit(node.value, newnode),
[self.visit(child, newnode) for child in node.generators],
)
return newnode | [
"def",
"visit_dictcomp",
"(",
"self",
",",
"node",
",",
"parent",
")",
":",
"newnode",
"=",
"nodes",
".",
"DictComp",
"(",
"node",
".",
"lineno",
",",
"node",
".",
"col_offset",
",",
"parent",
")",
"newnode",
".",
"postinit",
"(",
"self",
".",
"visit",... | visit a DictComp node by returning a fresh instance of it | [
"visit",
"a",
"DictComp",
"node",
"by",
"returning",
"a",
"fresh",
"instance",
"of",
"it"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/rebuilder.py#L489-L497 |
227,129 | PyCQA/astroid | astroid/rebuilder.py | TreeRebuilder.visit_expr | 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)
newnode.postinit(self.visit(node.value, newnode))
return newnode | python | def visit_expr(self, node, parent):
newnode = nodes.Expr(node.lineno, node.col_offset, parent)
newnode.postinit(self.visit(node.value, newnode))
return newnode | [
"def",
"visit_expr",
"(",
"self",
",",
"node",
",",
"parent",
")",
":",
"newnode",
"=",
"nodes",
".",
"Expr",
"(",
"node",
".",
"lineno",
",",
"node",
".",
"col_offset",
",",
"parent",
")",
"newnode",
".",
"postinit",
"(",
"self",
".",
"visit",
"(",
... | visit a Expr node by returning a fresh instance of it | [
"visit",
"a",
"Expr",
"node",
"by",
"returning",
"a",
"fresh",
"instance",
"of",
"it"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/rebuilder.py#L499-L503 |
227,130 | PyCQA/astroid | astroid/rebuilder.py | TreeRebuilder.visit_ellipsis | def visit_ellipsis(self, node, parent):
"""visit an Ellipsis node by returning a fresh instance of it"""
return nodes.Ellipsis(
getattr(node, "lineno", None), getattr(node, "col_offset", None), parent
) | python | def visit_ellipsis(self, node, parent):
return nodes.Ellipsis(
getattr(node, "lineno", None), getattr(node, "col_offset", None), parent
) | [
"def",
"visit_ellipsis",
"(",
"self",
",",
"node",
",",
"parent",
")",
":",
"return",
"nodes",
".",
"Ellipsis",
"(",
"getattr",
"(",
"node",
",",
"\"lineno\"",
",",
"None",
")",
",",
"getattr",
"(",
"node",
",",
"\"col_offset\"",
",",
"None",
")",
",",... | visit an Ellipsis node by returning a fresh instance of it | [
"visit",
"an",
"Ellipsis",
"node",
"by",
"returning",
"a",
"fresh",
"instance",
"of",
"it"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/rebuilder.py#L506-L510 |
227,131 | PyCQA/astroid | astroid/rebuilder.py | TreeRebuilder.visit_emptynode | def visit_emptynode(self, node, parent):
"""visit an EmptyNode node by returning a fresh instance of it"""
return nodes.EmptyNode(
getattr(node, "lineno", None), getattr(node, "col_offset", None), parent
) | python | def visit_emptynode(self, node, parent):
return nodes.EmptyNode(
getattr(node, "lineno", None), getattr(node, "col_offset", None), parent
) | [
"def",
"visit_emptynode",
"(",
"self",
",",
"node",
",",
"parent",
")",
":",
"return",
"nodes",
".",
"EmptyNode",
"(",
"getattr",
"(",
"node",
",",
"\"lineno\"",
",",
"None",
")",
",",
"getattr",
"(",
"node",
",",
"\"col_offset\"",
",",
"None",
")",
",... | visit an EmptyNode node by returning a fresh instance of it | [
"visit",
"an",
"EmptyNode",
"node",
"by",
"returning",
"a",
"fresh",
"instance",
"of",
"it"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/rebuilder.py#L512-L516 |
227,132 | PyCQA/astroid | astroid/rebuilder.py | TreeRebuilder.visit_exec | 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),
_visit_or_none(node, "globals", self, newnode),
_visit_or_none(node, "locals", self, newnode),
)
return newnode | python | def visit_exec(self, node, parent):
newnode = nodes.Exec(node.lineno, node.col_offset, parent)
newnode.postinit(
self.visit(node.body, newnode),
_visit_or_none(node, "globals", self, newnode),
_visit_or_none(node, "locals", self, newnode),
)
return newnode | [
"def",
"visit_exec",
"(",
"self",
",",
"node",
",",
"parent",
")",
":",
"newnode",
"=",
"nodes",
".",
"Exec",
"(",
"node",
".",
"lineno",
",",
"node",
".",
"col_offset",
",",
"parent",
")",
"newnode",
".",
"postinit",
"(",
"self",
".",
"visit",
"(",
... | visit an Exec node by returning a fresh instance of it | [
"visit",
"an",
"Exec",
"node",
"by",
"returning",
"a",
"fresh",
"instance",
"of",
"it"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/rebuilder.py#L529-L537 |
227,133 | PyCQA/astroid | astroid/rebuilder.py | TreeRebuilder.visit_extslice | def visit_extslice(self, node, parent):
"""visit an ExtSlice node by returning a fresh instance of it"""
newnode = nodes.ExtSlice(parent=parent)
newnode.postinit([self.visit(dim, newnode) for dim in node.dims])
return newnode | python | def visit_extslice(self, node, parent):
newnode = nodes.ExtSlice(parent=parent)
newnode.postinit([self.visit(dim, newnode) for dim in node.dims])
return newnode | [
"def",
"visit_extslice",
"(",
"self",
",",
"node",
",",
"parent",
")",
":",
"newnode",
"=",
"nodes",
".",
"ExtSlice",
"(",
"parent",
"=",
"parent",
")",
"newnode",
".",
"postinit",
"(",
"[",
"self",
".",
"visit",
"(",
"dim",
",",
"newnode",
")",
"for... | visit an ExtSlice node by returning a fresh instance of it | [
"visit",
"an",
"ExtSlice",
"node",
"by",
"returning",
"a",
"fresh",
"instance",
"of",
"it"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/rebuilder.py#L540-L544 |
227,134 | PyCQA/astroid | astroid/rebuilder.py | TreeRebuilder._visit_for | 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=self.visit(node.iter, newnode),
body=[self.visit(child, newnode) for child in node.body],
orelse=[self.visit(child, newnode) for child in node.orelse],
type_annotation=type_annotation,
)
return newnode | python | def _visit_for(self, cls, node, parent):
newnode = cls(node.lineno, node.col_offset, parent)
type_annotation = self.check_type_comment(node)
newnode.postinit(
target=self.visit(node.target, newnode),
iter=self.visit(node.iter, newnode),
body=[self.visit(child, newnode) for child in node.body],
orelse=[self.visit(child, newnode) for child in node.orelse],
type_annotation=type_annotation,
)
return newnode | [
"def",
"_visit_for",
"(",
"self",
",",
"cls",
",",
"node",
",",
"parent",
")",
":",
"newnode",
"=",
"cls",
"(",
"node",
".",
"lineno",
",",
"node",
".",
"col_offset",
",",
"parent",
")",
"type_annotation",
"=",
"self",
".",
"check_type_comment",
"(",
"... | visit a For node by returning a fresh instance of it | [
"visit",
"a",
"For",
"node",
"by",
"returning",
"a",
"fresh",
"instance",
"of",
"it"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/rebuilder.py#L546-L557 |
227,135 | PyCQA/astroid | astroid/rebuilder.py | TreeRebuilder.visit_importfrom | 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(
node.module or "",
names,
node.level or None,
getattr(node, "lineno", None),
getattr(node, "col_offset", None),
parent,
)
# store From names to add them to locals after building
self._import_from_nodes.append(newnode)
return newnode | python | def visit_importfrom(self, node, parent):
names = [(alias.name, alias.asname) for alias in node.names]
newnode = nodes.ImportFrom(
node.module or "",
names,
node.level or None,
getattr(node, "lineno", None),
getattr(node, "col_offset", None),
parent,
)
# store From names to add them to locals after building
self._import_from_nodes.append(newnode)
return newnode | [
"def",
"visit_importfrom",
"(",
"self",
",",
"node",
",",
"parent",
")",
":",
"names",
"=",
"[",
"(",
"alias",
".",
"name",
",",
"alias",
".",
"asname",
")",
"for",
"alias",
"in",
"node",
".",
"names",
"]",
"newnode",
"=",
"nodes",
".",
"ImportFrom",... | visit an ImportFrom node by returning a fresh instance of it | [
"visit",
"an",
"ImportFrom",
"node",
"by",
"returning",
"a",
"fresh",
"instance",
"of",
"it"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/rebuilder.py#L562-L575 |
227,136 | PyCQA/astroid | astroid/rebuilder.py | TreeRebuilder._visit_functiondef | 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 = self.visit_decorators(node, newnode)
else:
decorators = None
if PY3 and node.returns:
returns = self.visit(node.returns, newnode)
else:
returns = None
type_comment_args = type_comment_returns = None
type_comment_annotation = self.check_function_type_comment(node)
if type_comment_annotation:
type_comment_returns, type_comment_args = type_comment_annotation
newnode.postinit(
args=self.visit(node.args, newnode),
body=[self.visit(child, newnode) for child in node.body],
decorators=decorators,
returns=returns,
type_comment_returns=type_comment_returns,
type_comment_args=type_comment_args,
)
self._global_names.pop()
return newnode | python | def _visit_functiondef(self, cls, node, parent):
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 = self.visit_decorators(node, newnode)
else:
decorators = None
if PY3 and node.returns:
returns = self.visit(node.returns, newnode)
else:
returns = None
type_comment_args = type_comment_returns = None
type_comment_annotation = self.check_function_type_comment(node)
if type_comment_annotation:
type_comment_returns, type_comment_args = type_comment_annotation
newnode.postinit(
args=self.visit(node.args, newnode),
body=[self.visit(child, newnode) for child in node.body],
decorators=decorators,
returns=returns,
type_comment_returns=type_comment_returns,
type_comment_args=type_comment_args,
)
self._global_names.pop()
return newnode | [
"def",
"_visit_functiondef",
"(",
"self",
",",
"cls",
",",
"node",
",",
"parent",
")",
":",
"self",
".",
"_global_names",
".",
"append",
"(",
"{",
"}",
")",
"node",
",",
"doc",
"=",
"self",
".",
"_get_doc",
"(",
"node",
")",
"newnode",
"=",
"cls",
... | visit an FunctionDef node to become astroid | [
"visit",
"an",
"FunctionDef",
"node",
"to",
"become",
"astroid"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/rebuilder.py#L577-L604 |
227,137 | PyCQA/astroid | astroid/rebuilder.py | TreeRebuilder.visit_generatorexp | 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(
self.visit(node.elt, newnode),
[self.visit(child, newnode) for child in node.generators],
)
return newnode | python | def visit_generatorexp(self, node, parent):
newnode = nodes.GeneratorExp(node.lineno, node.col_offset, parent)
newnode.postinit(
self.visit(node.elt, newnode),
[self.visit(child, newnode) for child in node.generators],
)
return newnode | [
"def",
"visit_generatorexp",
"(",
"self",
",",
"node",
",",
"parent",
")",
":",
"newnode",
"=",
"nodes",
".",
"GeneratorExp",
"(",
"node",
".",
"lineno",
",",
"node",
".",
"col_offset",
",",
"parent",
")",
"newnode",
".",
"postinit",
"(",
"self",
".",
... | visit a GeneratorExp node by returning a fresh instance of it | [
"visit",
"a",
"GeneratorExp",
"node",
"by",
"returning",
"a",
"fresh",
"instance",
"of",
"it"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/rebuilder.py#L609-L616 |
227,138 | PyCQA/astroid | astroid/rebuilder.py | TreeRebuilder.visit_attribute | 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
newnode = nodes.DelAttr(node.attr, node.lineno, node.col_offset, parent)
elif context == astroid.Store:
newnode = nodes.AssignAttr(node.attr, node.lineno, node.col_offset, parent)
# Prohibit a local save if we are in an ExceptHandler.
if not isinstance(parent, astroid.ExceptHandler):
self._delayed_assattr.append(newnode)
else:
newnode = nodes.Attribute(node.attr, node.lineno, node.col_offset, parent)
newnode.postinit(self.visit(node.value, newnode))
return newnode | python | def visit_attribute(self, node, parent):
context = self._get_context(node)
if context == astroid.Del:
# FIXME : maybe we should reintroduce and visit_delattr ?
# for instance, deactivating assign_ctx
newnode = nodes.DelAttr(node.attr, node.lineno, node.col_offset, parent)
elif context == astroid.Store:
newnode = nodes.AssignAttr(node.attr, node.lineno, node.col_offset, parent)
# Prohibit a local save if we are in an ExceptHandler.
if not isinstance(parent, astroid.ExceptHandler):
self._delayed_assattr.append(newnode)
else:
newnode = nodes.Attribute(node.attr, node.lineno, node.col_offset, parent)
newnode.postinit(self.visit(node.value, newnode))
return newnode | [
"def",
"visit_attribute",
"(",
"self",
",",
"node",
",",
"parent",
")",
":",
"context",
"=",
"self",
".",
"_get_context",
"(",
"node",
")",
"if",
"context",
"==",
"astroid",
".",
"Del",
":",
"# FIXME : maybe we should reintroduce and visit_delattr ?",
"# for insta... | visit an Attribute node by returning a fresh instance of it | [
"visit",
"an",
"Attribute",
"node",
"by",
"returning",
"a",
"fresh",
"instance",
"of",
"it"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/rebuilder.py#L618-L633 |
227,139 | PyCQA/astroid | astroid/rebuilder.py | TreeRebuilder.visit_global | 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,
)
if self._global_names: # global at the module level, no effect
for name in node.names:
self._global_names[-1].setdefault(name, []).append(newnode)
return newnode | python | def visit_global(self, node, parent):
newnode = nodes.Global(
node.names,
getattr(node, "lineno", None),
getattr(node, "col_offset", None),
parent,
)
if self._global_names: # global at the module level, no effect
for name in node.names:
self._global_names[-1].setdefault(name, []).append(newnode)
return newnode | [
"def",
"visit_global",
"(",
"self",
",",
"node",
",",
"parent",
")",
":",
"newnode",
"=",
"nodes",
".",
"Global",
"(",
"node",
".",
"names",
",",
"getattr",
"(",
"node",
",",
"\"lineno\"",
",",
"None",
")",
",",
"getattr",
"(",
"node",
",",
"\"col_of... | visit a Global node to become astroid | [
"visit",
"a",
"Global",
"node",
"to",
"become",
"astroid"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/rebuilder.py#L635-L646 |
227,140 | PyCQA/astroid | astroid/rebuilder.py | TreeRebuilder.visit_if | 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, newnode) for child in node.body],
[self.visit(child, newnode) for child in node.orelse],
)
return newnode | python | def visit_if(self, node, parent):
newnode = nodes.If(node.lineno, node.col_offset, parent)
newnode.postinit(
self.visit(node.test, newnode),
[self.visit(child, newnode) for child in node.body],
[self.visit(child, newnode) for child in node.orelse],
)
return newnode | [
"def",
"visit_if",
"(",
"self",
",",
"node",
",",
"parent",
")",
":",
"newnode",
"=",
"nodes",
".",
"If",
"(",
"node",
".",
"lineno",
",",
"node",
".",
"col_offset",
",",
"parent",
")",
"newnode",
".",
"postinit",
"(",
"self",
".",
"visit",
"(",
"n... | visit an If node by returning a fresh instance of it | [
"visit",
"an",
"If",
"node",
"by",
"returning",
"a",
"fresh",
"instance",
"of",
"it"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/rebuilder.py#L648-L656 |
227,141 | PyCQA/astroid | astroid/rebuilder.py | TreeRebuilder.visit_ifexp | 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),
self.visit(node.body, newnode),
self.visit(node.orelse, newnode),
)
return newnode | python | def visit_ifexp(self, node, parent):
newnode = nodes.IfExp(node.lineno, node.col_offset, parent)
newnode.postinit(
self.visit(node.test, newnode),
self.visit(node.body, newnode),
self.visit(node.orelse, newnode),
)
return newnode | [
"def",
"visit_ifexp",
"(",
"self",
",",
"node",
",",
"parent",
")",
":",
"newnode",
"=",
"nodes",
".",
"IfExp",
"(",
"node",
".",
"lineno",
",",
"node",
".",
"col_offset",
",",
"parent",
")",
"newnode",
".",
"postinit",
"(",
"self",
".",
"visit",
"("... | visit a IfExp node by returning a fresh instance of it | [
"visit",
"a",
"IfExp",
"node",
"by",
"returning",
"a",
"fresh",
"instance",
"of",
"it"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/rebuilder.py#L658-L666 |
227,142 | PyCQA/astroid | astroid/rebuilder.py | TreeRebuilder.visit_import | 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,
getattr(node, "lineno", None),
getattr(node, "col_offset", None),
parent,
)
# save import names in parent's locals:
for (name, asname) in newnode.names:
name = asname or name
parent.set_local(name.split(".")[0], newnode)
return newnode | python | def visit_import(self, node, parent):
names = [(alias.name, alias.asname) for alias in node.names]
newnode = nodes.Import(
names,
getattr(node, "lineno", None),
getattr(node, "col_offset", None),
parent,
)
# save import names in parent's locals:
for (name, asname) in newnode.names:
name = asname or name
parent.set_local(name.split(".")[0], newnode)
return newnode | [
"def",
"visit_import",
"(",
"self",
",",
"node",
",",
"parent",
")",
":",
"names",
"=",
"[",
"(",
"alias",
".",
"name",
",",
"alias",
".",
"asname",
")",
"for",
"alias",
"in",
"node",
".",
"names",
"]",
"newnode",
"=",
"nodes",
".",
"Import",
"(",
... | visit a Import node by returning a fresh instance of it | [
"visit",
"a",
"Import",
"node",
"by",
"returning",
"a",
"fresh",
"instance",
"of",
"it"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/rebuilder.py#L668-L681 |
227,143 | PyCQA/astroid | astroid/rebuilder.py | TreeRebuilder.visit_index | def visit_index(self, node, parent):
"""visit a Index node by returning a fresh instance of it"""
newnode = nodes.Index(parent=parent)
newnode.postinit(self.visit(node.value, newnode))
return newnode | python | def visit_index(self, node, parent):
newnode = nodes.Index(parent=parent)
newnode.postinit(self.visit(node.value, newnode))
return newnode | [
"def",
"visit_index",
"(",
"self",
",",
"node",
",",
"parent",
")",
":",
"newnode",
"=",
"nodes",
".",
"Index",
"(",
"parent",
"=",
"parent",
")",
"newnode",
".",
"postinit",
"(",
"self",
".",
"visit",
"(",
"node",
".",
"value",
",",
"newnode",
")",
... | visit a Index node by returning a fresh instance of it | [
"visit",
"a",
"Index",
"node",
"by",
"returning",
"a",
"fresh",
"instance",
"of",
"it"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/rebuilder.py#L684-L688 |
227,144 | PyCQA/astroid | astroid/rebuilder.py | TreeRebuilder.visit_keyword | def visit_keyword(self, node, parent):
"""visit a Keyword node by returning a fresh instance of it"""
newnode = nodes.Keyword(node.arg, parent=parent)
newnode.postinit(self.visit(node.value, newnode))
return newnode | python | def visit_keyword(self, node, parent):
newnode = nodes.Keyword(node.arg, parent=parent)
newnode.postinit(self.visit(node.value, newnode))
return newnode | [
"def",
"visit_keyword",
"(",
"self",
",",
"node",
",",
"parent",
")",
":",
"newnode",
"=",
"nodes",
".",
"Keyword",
"(",
"node",
".",
"arg",
",",
"parent",
"=",
"parent",
")",
"newnode",
".",
"postinit",
"(",
"self",
".",
"visit",
"(",
"node",
".",
... | visit a Keyword node by returning a fresh instance of it | [
"visit",
"a",
"Keyword",
"node",
"by",
"returning",
"a",
"fresh",
"instance",
"of",
"it"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/rebuilder.py#L690-L694 |
227,145 | PyCQA/astroid | astroid/rebuilder.py | TreeRebuilder.visit_lambda | 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)
newnode.postinit(self.visit(node.args, newnode), self.visit(node.body, newnode))
return newnode | python | def visit_lambda(self, node, parent):
newnode = nodes.Lambda(node.lineno, node.col_offset, parent)
newnode.postinit(self.visit(node.args, newnode), self.visit(node.body, newnode))
return newnode | [
"def",
"visit_lambda",
"(",
"self",
",",
"node",
",",
"parent",
")",
":",
"newnode",
"=",
"nodes",
".",
"Lambda",
"(",
"node",
".",
"lineno",
",",
"node",
".",
"col_offset",
",",
"parent",
")",
"newnode",
".",
"postinit",
"(",
"self",
".",
"visit",
"... | visit a Lambda node by returning a fresh instance of it | [
"visit",
"a",
"Lambda",
"node",
"by",
"returning",
"a",
"fresh",
"instance",
"of",
"it"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/rebuilder.py#L696-L700 |
227,146 | PyCQA/astroid | astroid/rebuilder.py | TreeRebuilder.visit_list | 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(
ctx=context, lineno=node.lineno, col_offset=node.col_offset, parent=parent
)
newnode.postinit([self.visit(child, newnode) for child in node.elts])
return newnode | python | def visit_list(self, node, parent):
context = self._get_context(node)
newnode = nodes.List(
ctx=context, lineno=node.lineno, col_offset=node.col_offset, parent=parent
)
newnode.postinit([self.visit(child, newnode) for child in node.elts])
return newnode | [
"def",
"visit_list",
"(",
"self",
",",
"node",
",",
"parent",
")",
":",
"context",
"=",
"self",
".",
"_get_context",
"(",
"node",
")",
"newnode",
"=",
"nodes",
".",
"List",
"(",
"ctx",
"=",
"context",
",",
"lineno",
"=",
"node",
".",
"lineno",
",",
... | visit a List node by returning a fresh instance of it | [
"visit",
"a",
"List",
"node",
"by",
"returning",
"a",
"fresh",
"instance",
"of",
"it"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/rebuilder.py#L702-L709 |
227,147 | PyCQA/astroid | astroid/rebuilder.py | TreeRebuilder.visit_listcomp | 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(
self.visit(node.elt, newnode),
[self.visit(child, newnode) for child in node.generators],
)
return newnode | python | def visit_listcomp(self, node, parent):
newnode = nodes.ListComp(node.lineno, node.col_offset, parent)
newnode.postinit(
self.visit(node.elt, newnode),
[self.visit(child, newnode) for child in node.generators],
)
return newnode | [
"def",
"visit_listcomp",
"(",
"self",
",",
"node",
",",
"parent",
")",
":",
"newnode",
"=",
"nodes",
".",
"ListComp",
"(",
"node",
".",
"lineno",
",",
"node",
".",
"col_offset",
",",
"parent",
")",
"newnode",
".",
"postinit",
"(",
"self",
".",
"visit",... | visit a ListComp node by returning a fresh instance of it | [
"visit",
"a",
"ListComp",
"node",
"by",
"returning",
"a",
"fresh",
"instance",
"of",
"it"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/rebuilder.py#L711-L718 |
227,148 | PyCQA/astroid | astroid/rebuilder.py | TreeRebuilder.visit_name | 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.DelName(node.id, node.lineno, node.col_offset, parent)
elif context == astroid.Store:
newnode = nodes.AssignName(node.id, node.lineno, node.col_offset, parent)
elif node.id in CONST_NAME_TRANSFORMS:
newnode = nodes.Const(
CONST_NAME_TRANSFORMS[node.id],
getattr(node, "lineno", None),
getattr(node, "col_offset", None),
parent,
)
return newnode
else:
newnode = nodes.Name(node.id, node.lineno, node.col_offset, parent)
# XXX REMOVE me :
if context in (astroid.Del, astroid.Store): # 'Aug' ??
self._save_assignment(newnode)
return newnode | python | def visit_name(self, node, parent):
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.DelName(node.id, node.lineno, node.col_offset, parent)
elif context == astroid.Store:
newnode = nodes.AssignName(node.id, node.lineno, node.col_offset, parent)
elif node.id in CONST_NAME_TRANSFORMS:
newnode = nodes.Const(
CONST_NAME_TRANSFORMS[node.id],
getattr(node, "lineno", None),
getattr(node, "col_offset", None),
parent,
)
return newnode
else:
newnode = nodes.Name(node.id, node.lineno, node.col_offset, parent)
# XXX REMOVE me :
if context in (astroid.Del, astroid.Store): # 'Aug' ??
self._save_assignment(newnode)
return newnode | [
"def",
"visit_name",
"(",
"self",
",",
"node",
",",
"parent",
")",
":",
"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",... | visit a Name node by returning a fresh instance of it | [
"visit",
"a",
"Name",
"node",
"by",
"returning",
"a",
"fresh",
"instance",
"of",
"it"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/rebuilder.py#L720-L742 |
227,149 | PyCQA/astroid | astroid/rebuilder.py | TreeRebuilder.visit_constant | def visit_constant(self, node, parent):
"""visit a Constant node by returning a fresh instance of Const"""
return nodes.Const(
node.value,
getattr(node, "lineno", None),
getattr(node, "col_offset", None),
parent,
) | python | def visit_constant(self, node, parent):
return nodes.Const(
node.value,
getattr(node, "lineno", None),
getattr(node, "col_offset", None),
parent,
) | [
"def",
"visit_constant",
"(",
"self",
",",
"node",
",",
"parent",
")",
":",
"return",
"nodes",
".",
"Const",
"(",
"node",
".",
"value",
",",
"getattr",
"(",
"node",
",",
"\"lineno\"",
",",
"None",
")",
",",
"getattr",
"(",
"node",
",",
"\"col_offset\""... | visit a Constant node by returning a fresh instance of Const | [
"visit",
"a",
"Constant",
"node",
"by",
"returning",
"a",
"fresh",
"instance",
"of",
"Const"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/rebuilder.py#L744-L751 |
227,150 | PyCQA/astroid | astroid/rebuilder.py | TreeRebuilder.visit_num | def visit_num(self, node, parent):
"""visit a Num node by returning a fresh instance of Const"""
return nodes.Const(
node.n,
getattr(node, "lineno", None),
getattr(node, "col_offset", None),
parent,
) | python | def visit_num(self, node, parent):
return nodes.Const(
node.n,
getattr(node, "lineno", None),
getattr(node, "col_offset", None),
parent,
) | [
"def",
"visit_num",
"(",
"self",
",",
"node",
",",
"parent",
")",
":",
"return",
"nodes",
".",
"Const",
"(",
"node",
".",
"n",
",",
"getattr",
"(",
"node",
",",
"\"lineno\"",
",",
"None",
")",
",",
"getattr",
"(",
"node",
",",
"\"col_offset\"",
",",
... | visit a Num node by returning a fresh instance of Const | [
"visit",
"a",
"Num",
"node",
"by",
"returning",
"a",
"fresh",
"instance",
"of",
"Const"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/rebuilder.py#L766-L773 |
227,151 | PyCQA/astroid | astroid/rebuilder.py | TreeRebuilder.visit_pass | def visit_pass(self, node, parent):
"""visit a Pass node by returning a fresh instance of it"""
return nodes.Pass(node.lineno, node.col_offset, parent) | python | def visit_pass(self, node, parent):
return nodes.Pass(node.lineno, node.col_offset, parent) | [
"def",
"visit_pass",
"(",
"self",
",",
"node",
",",
"parent",
")",
":",
"return",
"nodes",
".",
"Pass",
"(",
"node",
".",
"lineno",
",",
"node",
".",
"col_offset",
",",
"parent",
")"
] | visit a Pass node by returning a fresh instance of it | [
"visit",
"a",
"Pass",
"node",
"by",
"returning",
"a",
"fresh",
"instance",
"of",
"it"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/rebuilder.py#L775-L777 |
227,152 | PyCQA/astroid | astroid/rebuilder.py | TreeRebuilder.visit_print | 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(
_visit_or_none(node, "dest", self, newnode),
[self.visit(child, newnode) for child in node.values],
)
return newnode | python | def visit_print(self, node, parent):
newnode = nodes.Print(node.nl, node.lineno, node.col_offset, parent)
newnode.postinit(
_visit_or_none(node, "dest", self, newnode),
[self.visit(child, newnode) for child in node.values],
)
return newnode | [
"def",
"visit_print",
"(",
"self",
",",
"node",
",",
"parent",
")",
":",
"newnode",
"=",
"nodes",
".",
"Print",
"(",
"node",
".",
"nl",
",",
"node",
".",
"lineno",
",",
"node",
".",
"col_offset",
",",
"parent",
")",
"newnode",
".",
"postinit",
"(",
... | visit a Print node by returning a fresh instance of it | [
"visit",
"a",
"Print",
"node",
"by",
"returning",
"a",
"fresh",
"instance",
"of",
"it"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/rebuilder.py#L779-L786 |
227,153 | PyCQA/astroid | astroid/rebuilder.py | TreeRebuilder.visit_raise | 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),
_visit_or_none(node, "inst", self, newnode),
_visit_or_none(node, "tback", self, newnode),
)
return newnode | python | def visit_raise(self, node, parent):
newnode = nodes.Raise(node.lineno, node.col_offset, parent)
# pylint: disable=too-many-function-args
newnode.postinit(
_visit_or_none(node, "type", self, newnode),
_visit_or_none(node, "inst", self, newnode),
_visit_or_none(node, "tback", self, newnode),
)
return newnode | [
"def",
"visit_raise",
"(",
"self",
",",
"node",
",",
"parent",
")",
":",
"newnode",
"=",
"nodes",
".",
"Raise",
"(",
"node",
".",
"lineno",
",",
"node",
".",
"col_offset",
",",
"parent",
")",
"# pylint: disable=too-many-function-args",
"newnode",
".",
"posti... | visit a Raise node by returning a fresh instance of it | [
"visit",
"a",
"Raise",
"node",
"by",
"returning",
"a",
"fresh",
"instance",
"of",
"it"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/rebuilder.py#L788-L797 |
227,154 | PyCQA/astroid | astroid/rebuilder.py | TreeRebuilder.visit_return | def visit_return(self, node, parent):
"""visit a Return node by returning a fresh instance of it"""
newnode = nodes.Return(node.lineno, node.col_offset, parent)
if node.value is not None:
newnode.postinit(self.visit(node.value, newnode))
return newnode | python | def visit_return(self, node, parent):
newnode = nodes.Return(node.lineno, node.col_offset, parent)
if node.value is not None:
newnode.postinit(self.visit(node.value, newnode))
return newnode | [
"def",
"visit_return",
"(",
"self",
",",
"node",
",",
"parent",
")",
":",
"newnode",
"=",
"nodes",
".",
"Return",
"(",
"node",
".",
"lineno",
",",
"node",
".",
"col_offset",
",",
"parent",
")",
"if",
"node",
".",
"value",
"is",
"not",
"None",
":",
... | visit a Return node by returning a fresh instance of it | [
"visit",
"a",
"Return",
"node",
"by",
"returning",
"a",
"fresh",
"instance",
"of",
"it"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/rebuilder.py#L799-L804 |
227,155 | PyCQA/astroid | astroid/rebuilder.py | TreeRebuilder.visit_set | def visit_set(self, node, parent):
"""visit a Set node by returning a fresh instance of it"""
newnode = nodes.Set(node.lineno, node.col_offset, parent)
newnode.postinit([self.visit(child, newnode) for child in node.elts])
return newnode | python | def visit_set(self, node, parent):
newnode = nodes.Set(node.lineno, node.col_offset, parent)
newnode.postinit([self.visit(child, newnode) for child in node.elts])
return newnode | [
"def",
"visit_set",
"(",
"self",
",",
"node",
",",
"parent",
")",
":",
"newnode",
"=",
"nodes",
".",
"Set",
"(",
"node",
".",
"lineno",
",",
"node",
".",
"col_offset",
",",
"parent",
")",
"newnode",
".",
"postinit",
"(",
"[",
"self",
".",
"visit",
... | visit a Set node by returning a fresh instance of it | [
"visit",
"a",
"Set",
"node",
"by",
"returning",
"a",
"fresh",
"instance",
"of",
"it"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/rebuilder.py#L806-L810 |
227,156 | PyCQA/astroid | astroid/rebuilder.py | TreeRebuilder.visit_setcomp | 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(
self.visit(node.elt, newnode),
[self.visit(child, newnode) for child in node.generators],
)
return newnode | python | def visit_setcomp(self, node, parent):
newnode = nodes.SetComp(node.lineno, node.col_offset, parent)
newnode.postinit(
self.visit(node.elt, newnode),
[self.visit(child, newnode) for child in node.generators],
)
return newnode | [
"def",
"visit_setcomp",
"(",
"self",
",",
"node",
",",
"parent",
")",
":",
"newnode",
"=",
"nodes",
".",
"SetComp",
"(",
"node",
".",
"lineno",
",",
"node",
".",
"col_offset",
",",
"parent",
")",
"newnode",
".",
"postinit",
"(",
"self",
".",
"visit",
... | visit a SetComp node by returning a fresh instance of it | [
"visit",
"a",
"SetComp",
"node",
"by",
"returning",
"a",
"fresh",
"instance",
"of",
"it"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/rebuilder.py#L812-L819 |
227,157 | PyCQA/astroid | astroid/rebuilder.py | TreeRebuilder.visit_slice | 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, "upper", self, newnode),
_visit_or_none(node, "step", self, newnode),
)
return newnode | python | def visit_slice(self, node, parent):
newnode = nodes.Slice(parent=parent)
newnode.postinit(
_visit_or_none(node, "lower", self, newnode),
_visit_or_none(node, "upper", self, newnode),
_visit_or_none(node, "step", self, newnode),
)
return newnode | [
"def",
"visit_slice",
"(",
"self",
",",
"node",
",",
"parent",
")",
":",
"newnode",
"=",
"nodes",
".",
"Slice",
"(",
"parent",
"=",
"parent",
")",
"newnode",
".",
"postinit",
"(",
"_visit_or_none",
"(",
"node",
",",
"\"lower\"",
",",
"self",
",",
"newn... | visit a Slice node by returning a fresh instance of it | [
"visit",
"a",
"Slice",
"node",
"by",
"returning",
"a",
"fresh",
"instance",
"of",
"it"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/rebuilder.py#L821-L829 |
227,158 | PyCQA/astroid | astroid/rebuilder.py | TreeRebuilder.visit_subscript | 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(
ctx=context, lineno=node.lineno, col_offset=node.col_offset, parent=parent
)
newnode.postinit(
self.visit(node.value, newnode), self.visit(node.slice, newnode)
)
return newnode | python | def visit_subscript(self, node, parent):
context = self._get_context(node)
newnode = nodes.Subscript(
ctx=context, lineno=node.lineno, col_offset=node.col_offset, parent=parent
)
newnode.postinit(
self.visit(node.value, newnode), self.visit(node.slice, newnode)
)
return newnode | [
"def",
"visit_subscript",
"(",
"self",
",",
"node",
",",
"parent",
")",
":",
"context",
"=",
"self",
".",
"_get_context",
"(",
"node",
")",
"newnode",
"=",
"nodes",
".",
"Subscript",
"(",
"ctx",
"=",
"context",
",",
"lineno",
"=",
"node",
".",
"lineno"... | visit a Subscript node by returning a fresh instance of it | [
"visit",
"a",
"Subscript",
"node",
"by",
"returning",
"a",
"fresh",
"instance",
"of",
"it"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/rebuilder.py#L831-L840 |
227,159 | PyCQA/astroid | astroid/rebuilder.py | TreeRebuilder.visit_tryexcept | 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],
[self.visit(child, newnode) for child in node.handlers],
[self.visit(child, newnode) for child in node.orelse],
)
return newnode | python | def visit_tryexcept(self, node, parent):
newnode = nodes.TryExcept(node.lineno, node.col_offset, parent)
newnode.postinit(
[self.visit(child, newnode) for child in node.body],
[self.visit(child, newnode) for child in node.handlers],
[self.visit(child, newnode) for child in node.orelse],
)
return newnode | [
"def",
"visit_tryexcept",
"(",
"self",
",",
"node",
",",
"parent",
")",
":",
"newnode",
"=",
"nodes",
".",
"TryExcept",
"(",
"node",
".",
"lineno",
",",
"node",
".",
"col_offset",
",",
"parent",
")",
"newnode",
".",
"postinit",
"(",
"[",
"self",
".",
... | visit a TryExcept node by returning a fresh instance of it | [
"visit",
"a",
"TryExcept",
"node",
"by",
"returning",
"a",
"fresh",
"instance",
"of",
"it"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/rebuilder.py#L842-L850 |
227,160 | PyCQA/astroid | astroid/rebuilder.py | TreeRebuilder.visit_tryfinally | 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(
[self.visit(child, newnode) for child in node.body],
[self.visit(n, newnode) for n in node.finalbody],
)
return newnode | python | def visit_tryfinally(self, node, parent):
newnode = nodes.TryFinally(node.lineno, node.col_offset, parent)
newnode.postinit(
[self.visit(child, newnode) for child in node.body],
[self.visit(n, newnode) for n in node.finalbody],
)
return newnode | [
"def",
"visit_tryfinally",
"(",
"self",
",",
"node",
",",
"parent",
")",
":",
"newnode",
"=",
"nodes",
".",
"TryFinally",
"(",
"node",
".",
"lineno",
",",
"node",
".",
"col_offset",
",",
"parent",
")",
"newnode",
".",
"postinit",
"(",
"[",
"self",
".",... | visit a TryFinally node by returning a fresh instance of it | [
"visit",
"a",
"TryFinally",
"node",
"by",
"returning",
"a",
"fresh",
"instance",
"of",
"it"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/rebuilder.py#L852-L859 |
227,161 | PyCQA/astroid | astroid/rebuilder.py | TreeRebuilder.visit_tuple | 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(
ctx=context, lineno=node.lineno, col_offset=node.col_offset, parent=parent
)
newnode.postinit([self.visit(child, newnode) for child in node.elts])
return newnode | python | def visit_tuple(self, node, parent):
context = self._get_context(node)
newnode = nodes.Tuple(
ctx=context, lineno=node.lineno, col_offset=node.col_offset, parent=parent
)
newnode.postinit([self.visit(child, newnode) for child in node.elts])
return newnode | [
"def",
"visit_tuple",
"(",
"self",
",",
"node",
",",
"parent",
")",
":",
"context",
"=",
"self",
".",
"_get_context",
"(",
"node",
")",
"newnode",
"=",
"nodes",
".",
"Tuple",
"(",
"ctx",
"=",
"context",
",",
"lineno",
"=",
"node",
".",
"lineno",
",",... | visit a Tuple node by returning a fresh instance of it | [
"visit",
"a",
"Tuple",
"node",
"by",
"returning",
"a",
"fresh",
"instance",
"of",
"it"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/rebuilder.py#L861-L868 |
227,162 | PyCQA/astroid | astroid/rebuilder.py | TreeRebuilder.visit_unaryop | 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,
parent,
)
newnode.postinit(self.visit(node.operand, newnode))
return newnode | python | def visit_unaryop(self, node, parent):
newnode = nodes.UnaryOp(
self._unary_op_classes[node.op.__class__],
node.lineno,
node.col_offset,
parent,
)
newnode.postinit(self.visit(node.operand, newnode))
return newnode | [
"def",
"visit_unaryop",
"(",
"self",
",",
"node",
",",
"parent",
")",
":",
"newnode",
"=",
"nodes",
".",
"UnaryOp",
"(",
"self",
".",
"_unary_op_classes",
"[",
"node",
".",
"op",
".",
"__class__",
"]",
",",
"node",
".",
"lineno",
",",
"node",
".",
"c... | visit a UnaryOp node by returning a fresh instance of it | [
"visit",
"a",
"UnaryOp",
"node",
"by",
"returning",
"a",
"fresh",
"instance",
"of",
"it"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/rebuilder.py#L870-L879 |
227,163 | PyCQA/astroid | astroid/rebuilder.py | TreeRebuilder.visit_while | 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),
[self.visit(child, newnode) for child in node.body],
[self.visit(child, newnode) for child in node.orelse],
)
return newnode | python | def visit_while(self, node, parent):
newnode = nodes.While(node.lineno, node.col_offset, parent)
newnode.postinit(
self.visit(node.test, newnode),
[self.visit(child, newnode) for child in node.body],
[self.visit(child, newnode) for child in node.orelse],
)
return newnode | [
"def",
"visit_while",
"(",
"self",
",",
"node",
",",
"parent",
")",
":",
"newnode",
"=",
"nodes",
".",
"While",
"(",
"node",
".",
"lineno",
",",
"node",
".",
"col_offset",
",",
"parent",
")",
"newnode",
".",
"postinit",
"(",
"self",
".",
"visit",
"("... | visit a While node by returning a fresh instance of it | [
"visit",
"a",
"While",
"node",
"by",
"returning",
"a",
"fresh",
"instance",
"of",
"it"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/rebuilder.py#L881-L889 |
227,164 | PyCQA/astroid | astroid/rebuilder.py | TreeRebuilder.visit_yield | def visit_yield(self, node, parent):
"""visit a Yield node by returning a fresh instance of it"""
newnode = nodes.Yield(node.lineno, node.col_offset, parent)
if node.value is not None:
newnode.postinit(self.visit(node.value, newnode))
return newnode | python | def visit_yield(self, node, parent):
newnode = nodes.Yield(node.lineno, node.col_offset, parent)
if node.value is not None:
newnode.postinit(self.visit(node.value, newnode))
return newnode | [
"def",
"visit_yield",
"(",
"self",
",",
"node",
",",
"parent",
")",
":",
"newnode",
"=",
"nodes",
".",
"Yield",
"(",
"node",
".",
"lineno",
",",
"node",
".",
"col_offset",
",",
"parent",
")",
"if",
"node",
".",
"value",
"is",
"not",
"None",
":",
"n... | visit a Yield node by returning a fresh instance of it | [
"visit",
"a",
"Yield",
"node",
"by",
"returning",
"a",
"fresh",
"instance",
"of",
"it"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/rebuilder.py#L907-L912 |
227,165 | PyCQA/astroid | astroid/rebuilder.py | TreeRebuilder3.visit_arg | def visit_arg(self, node, parent):
"""visit an arg node by returning a fresh AssName instance"""
return self.visit_assignname(node, parent, node.arg) | python | def visit_arg(self, node, parent):
return self.visit_assignname(node, parent, node.arg) | [
"def",
"visit_arg",
"(",
"self",
",",
"node",
",",
"parent",
")",
":",
"return",
"self",
".",
"visit_assignname",
"(",
"node",
",",
"parent",
",",
"node",
".",
"arg",
")"
] | visit an arg node by returning a fresh AssName instance | [
"visit",
"an",
"arg",
"node",
"by",
"returning",
"a",
"fresh",
"AssName",
"instance"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/rebuilder.py#L918-L920 |
227,166 | PyCQA/astroid | astroid/rebuilder.py | TreeRebuilder3.visit_excepthandler | 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:
name = self.visit_assignname(node, newnode, node.name)
else:
name = None
newnode.postinit(
_visit_or_none(node, "type", self, newnode),
name,
[self.visit(child, newnode) for child in node.body],
)
return newnode | python | def visit_excepthandler(self, node, parent):
newnode = nodes.ExceptHandler(node.lineno, node.col_offset, parent)
if node.name:
name = self.visit_assignname(node, newnode, node.name)
else:
name = None
newnode.postinit(
_visit_or_none(node, "type", self, newnode),
name,
[self.visit(child, newnode) for child in node.body],
)
return newnode | [
"def",
"visit_excepthandler",
"(",
"self",
",",
"node",
",",
"parent",
")",
":",
"newnode",
"=",
"nodes",
".",
"ExceptHandler",
"(",
"node",
".",
"lineno",
",",
"node",
".",
"col_offset",
",",
"parent",
")",
"if",
"node",
".",
"name",
":",
"name",
"=",... | visit an ExceptHandler node by returning a fresh instance of it | [
"visit",
"an",
"ExceptHandler",
"node",
"by",
"returning",
"a",
"fresh",
"instance",
"of",
"it"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/rebuilder.py#L932-L944 |
227,167 | PyCQA/astroid | astroid/rebuilder.py | TreeRebuilder3.visit_nonlocal | def visit_nonlocal(self, node, parent):
"""visit a Nonlocal node and return a new instance of it"""
return nodes.Nonlocal(
node.names,
getattr(node, "lineno", None),
getattr(node, "col_offset", None),
parent,
) | python | def visit_nonlocal(self, node, parent):
return nodes.Nonlocal(
node.names,
getattr(node, "lineno", None),
getattr(node, "col_offset", None),
parent,
) | [
"def",
"visit_nonlocal",
"(",
"self",
",",
"node",
",",
"parent",
")",
":",
"return",
"nodes",
".",
"Nonlocal",
"(",
"node",
".",
"names",
",",
"getattr",
"(",
"node",
",",
"\"lineno\"",
",",
"None",
")",
",",
"getattr",
"(",
"node",
",",
"\"col_offset... | visit a Nonlocal node and return a new instance of it | [
"visit",
"a",
"Nonlocal",
"node",
"and",
"return",
"a",
"new",
"instance",
"of",
"it"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/rebuilder.py#L946-L953 |
227,168 | PyCQA/astroid | astroid/rebuilder.py | TreeRebuilder3.visit_starred | 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(
ctx=context, lineno=node.lineno, col_offset=node.col_offset, parent=parent
)
newnode.postinit(self.visit(node.value, newnode))
return newnode | python | def visit_starred(self, node, parent):
context = self._get_context(node)
newnode = nodes.Starred(
ctx=context, lineno=node.lineno, col_offset=node.col_offset, parent=parent
)
newnode.postinit(self.visit(node.value, newnode))
return newnode | [
"def",
"visit_starred",
"(",
"self",
",",
"node",
",",
"parent",
")",
":",
"context",
"=",
"self",
".",
"_get_context",
"(",
"node",
")",
"newnode",
"=",
"nodes",
".",
"Starred",
"(",
"ctx",
"=",
"context",
",",
"lineno",
"=",
"node",
".",
"lineno",
... | visit a Starred node and return a new instance of it | [
"visit",
"a",
"Starred",
"node",
"and",
"return",
"a",
"new",
"instance",
"of",
"it"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/rebuilder.py#L965-L972 |
227,169 | PyCQA/astroid | astroid/rebuilder.py | TreeRebuilder3.visit_annassign | 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.target, newnode),
annotation=annotation,
simple=node.simple,
value=_visit_or_none(node, "value", self, newnode),
)
return newnode | python | def visit_annassign(self, node, parent):
newnode = nodes.AnnAssign(node.lineno, node.col_offset, parent)
annotation = _visit_or_none(node, "annotation", self, newnode)
newnode.postinit(
target=self.visit(node.target, newnode),
annotation=annotation,
simple=node.simple,
value=_visit_or_none(node, "value", self, newnode),
)
return newnode | [
"def",
"visit_annassign",
"(",
"self",
",",
"node",
",",
"parent",
")",
":",
"newnode",
"=",
"nodes",
".",
"AnnAssign",
"(",
"node",
".",
"lineno",
",",
"node",
".",
"col_offset",
",",
"parent",
")",
"annotation",
"=",
"_visit_or_none",
"(",
"node",
",",... | visit an AnnAssign node by returning a fresh instance of it | [
"visit",
"an",
"AnnAssign",
"node",
"by",
"returning",
"a",
"fresh",
"instance",
"of",
"it"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/rebuilder.py#L989-L999 |
227,170 | PyCQA/astroid | astroid/manager.py | AstroidManager.ast_from_module | 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:
# some builtin modules don't have __file__ attribute
filepath = module.__file__
if modutils.is_python_source(filepath):
return self.ast_from_file(filepath, modname)
except AttributeError:
pass
from astroid.builder import AstroidBuilder
return AstroidBuilder(self).module_build(module, modname) | python | def ast_from_module(self, module, modname=None):
modname = modname or module.__name__
if modname in self.astroid_cache:
return self.astroid_cache[modname]
try:
# some builtin modules don't have __file__ attribute
filepath = module.__file__
if modutils.is_python_source(filepath):
return self.ast_from_file(filepath, modname)
except AttributeError:
pass
from astroid.builder import AstroidBuilder
return AstroidBuilder(self).module_build(module, modname) | [
"def",
"ast_from_module",
"(",
"self",
",",
"module",
",",
"modname",
"=",
"None",
")",
":",
"modname",
"=",
"modname",
"or",
"module",
".",
"__name__",
"if",
"modname",
"in",
"self",
".",
"astroid_cache",
":",
"return",
"self",
".",
"astroid_cache",
"[",
... | given an imported module, return the astroid object | [
"given",
"an",
"imported",
"module",
"return",
"the",
"astroid",
"object"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/manager.py#L225-L239 |
227,171 | PyCQA/astroid | astroid/manager.py | AstroidManager.ast_from_class | 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(
"Unable to get module for class {class_name}.",
cls=klass,
class_repr=safe_repr(klass),
modname=modname,
) from exc
modastroid = self.ast_from_module_name(modname)
return modastroid.getattr(klass.__name__)[0] | python | def ast_from_class(self, klass, modname=None):
if modname is None:
try:
modname = klass.__module__
except AttributeError as exc:
raise exceptions.AstroidBuildingError(
"Unable to get module for class {class_name}.",
cls=klass,
class_repr=safe_repr(klass),
modname=modname,
) from exc
modastroid = self.ast_from_module_name(modname)
return modastroid.getattr(klass.__name__)[0] | [
"def",
"ast_from_class",
"(",
"self",
",",
"klass",
",",
"modname",
"=",
"None",
")",
":",
"if",
"modname",
"is",
"None",
":",
"try",
":",
"modname",
"=",
"klass",
".",
"__module__",
"except",
"AttributeError",
"as",
"exc",
":",
"raise",
"exceptions",
".... | get astroid for the given class | [
"get",
"astroid",
"for",
"the",
"given",
"class"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/manager.py#L241-L254 |
227,172 | PyCQA/astroid | astroid/manager.py | AstroidManager.infer_ast_from_something | 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 AttributeError as exc:
raise exceptions.AstroidBuildingError(
"Unable to get module for {class_repr}.",
cls=klass,
class_repr=safe_repr(klass),
) from exc
except Exception as exc:
raise exceptions.AstroidImportError(
"Unexpected error while retrieving module for {class_repr}:\n"
"{error}",
cls=klass,
class_repr=safe_repr(klass),
) from exc
try:
name = klass.__name__
except AttributeError as exc:
raise exceptions.AstroidBuildingError(
"Unable to get name for {class_repr}:\n",
cls=klass,
class_repr=safe_repr(klass),
) from exc
except Exception as exc:
raise exceptions.AstroidImportError(
"Unexpected error while retrieving name for {class_repr}:\n" "{error}",
cls=klass,
class_repr=safe_repr(klass),
) from exc
# take care, on living object __module__ is regularly wrong :(
modastroid = self.ast_from_module_name(modname)
if klass is obj:
for inferred in modastroid.igetattr(name, context):
yield inferred
else:
for inferred in modastroid.igetattr(name, context):
yield inferred.instantiate_class() | python | def infer_ast_from_something(self, obj, context=None):
if hasattr(obj, "__class__") and not isinstance(obj, type):
klass = obj.__class__
else:
klass = obj
try:
modname = klass.__module__
except AttributeError as exc:
raise exceptions.AstroidBuildingError(
"Unable to get module for {class_repr}.",
cls=klass,
class_repr=safe_repr(klass),
) from exc
except Exception as exc:
raise exceptions.AstroidImportError(
"Unexpected error while retrieving module for {class_repr}:\n"
"{error}",
cls=klass,
class_repr=safe_repr(klass),
) from exc
try:
name = klass.__name__
except AttributeError as exc:
raise exceptions.AstroidBuildingError(
"Unable to get name for {class_repr}:\n",
cls=klass,
class_repr=safe_repr(klass),
) from exc
except Exception as exc:
raise exceptions.AstroidImportError(
"Unexpected error while retrieving name for {class_repr}:\n" "{error}",
cls=klass,
class_repr=safe_repr(klass),
) from exc
# take care, on living object __module__ is regularly wrong :(
modastroid = self.ast_from_module_name(modname)
if klass is obj:
for inferred in modastroid.igetattr(name, context):
yield inferred
else:
for inferred in modastroid.igetattr(name, context):
yield inferred.instantiate_class() | [
"def",
"infer_ast_from_something",
"(",
"self",
",",
"obj",
",",
"context",
"=",
"None",
")",
":",
"if",
"hasattr",
"(",
"obj",
",",
"\"__class__\"",
")",
"and",
"not",
"isinstance",
"(",
"obj",
",",
"type",
")",
":",
"klass",
"=",
"obj",
".",
"__class... | infer astroid for the given class | [
"infer",
"astroid",
"for",
"the",
"given",
"class"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/manager.py#L256-L298 |
227,173 | PyCQA/astroid | astroid/arguments.py | CallSite.from_call | def from_call(cls, call_node):
"""Get a CallSite object from the given Call node."""
callcontext = contextmod.CallContext(call_node.args, call_node.keywords)
return cls(callcontext) | python | def from_call(cls, call_node):
callcontext = contextmod.CallContext(call_node.args, call_node.keywords)
return cls(callcontext) | [
"def",
"from_call",
"(",
"cls",
",",
"call_node",
")",
":",
"callcontext",
"=",
"contextmod",
".",
"CallContext",
"(",
"call_node",
".",
"args",
",",
"call_node",
".",
"keywords",
")",
"return",
"cls",
"(",
"callcontext",
")"
] | Get a CallSite object from the given Call node. | [
"Get",
"a",
"CallSite",
"object",
"from",
"the",
"given",
"Call",
"node",
"."
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/arguments.py#L48-L51 |
227,174 | PyCQA/astroid | astroid/__init__.py | _inference_tip_cached | def _inference_tip_cached(func, instance, args, kwargs, _cache={}):
"""Cache decorator used for inference tips"""
node = args[0]
try:
return iter(_cache[func, node])
except KeyError:
result = func(*args, **kwargs)
# Need to keep an iterator around
original, copy = itertools.tee(result)
_cache[func, node] = list(copy)
return original | python | def _inference_tip_cached(func, instance, args, kwargs, _cache={}):
node = args[0]
try:
return iter(_cache[func, node])
except KeyError:
result = func(*args, **kwargs)
# Need to keep an iterator around
original, copy = itertools.tee(result)
_cache[func, node] = list(copy)
return original | [
"def",
"_inference_tip_cached",
"(",
"func",
",",
"instance",
",",
"args",
",",
"kwargs",
",",
"_cache",
"=",
"{",
"}",
")",
":",
"node",
"=",
"args",
"[",
"0",
"]",
"try",
":",
"return",
"iter",
"(",
"_cache",
"[",
"func",
",",
"node",
"]",
")",
... | Cache decorator used for inference tips | [
"Cache",
"decorator",
"used",
"for",
"inference",
"tips"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/__init__.py#L87-L97 |
227,175 | PyCQA/astroid | astroid/__init__.py | inference_tip | 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 overwrite another. Used for debugging
Typical usage
.. sourcecode:: python
MANAGER.register_transform(Call, inference_tip(infer_named_tuple),
predicate)
.. Note::
Using an inference tip will override
any previously set inference tip for the given
node. Use a predicate in the transform to prevent
excess overwrites.
"""
def transform(node, infer_function=infer_function):
if (
raise_on_overwrite
and node._explicit_inference is not None
and node._explicit_inference is not infer_function
):
raise InferenceOverwriteError(
"Inference already set to {existing_inference}. "
"Trying to overwrite with {new_inference} for {node}".format(
existing_inference=infer_function,
new_inference=node._explicit_inference,
node=node,
)
)
# pylint: disable=no-value-for-parameter
node._explicit_inference = _inference_tip_cached(infer_function)
return node
return transform | python | def inference_tip(infer_function, raise_on_overwrite=False):
def transform(node, infer_function=infer_function):
if (
raise_on_overwrite
and node._explicit_inference is not None
and node._explicit_inference is not infer_function
):
raise InferenceOverwriteError(
"Inference already set to {existing_inference}. "
"Trying to overwrite with {new_inference} for {node}".format(
existing_inference=infer_function,
new_inference=node._explicit_inference,
node=node,
)
)
# pylint: disable=no-value-for-parameter
node._explicit_inference = _inference_tip_cached(infer_function)
return node
return transform | [
"def",
"inference_tip",
"(",
"infer_function",
",",
"raise_on_overwrite",
"=",
"False",
")",
":",
"def",
"transform",
"(",
"node",
",",
"infer_function",
"=",
"infer_function",
")",
":",
"if",
"(",
"raise_on_overwrite",
"and",
"node",
".",
"_explicit_inference",
... | 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 overwrite another. Used for debugging
Typical usage
.. sourcecode:: python
MANAGER.register_transform(Call, inference_tip(infer_named_tuple),
predicate)
.. Note::
Using an inference tip will override
any previously set inference tip for the given
node. Use a predicate in the transform to prevent
excess overwrites. | [
"Given",
"an",
"instance",
"specific",
"inference",
"function",
"return",
"a",
"function",
"to",
"be",
"given",
"to",
"MANAGER",
".",
"register_transform",
"to",
"set",
"this",
"inference",
"function",
"."
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/__init__.py#L103-L143 |
227,176 | PyCQA/astroid | astroid/decorators.py | cached | 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:
return cache[func]
except KeyError:
cache[func] = result = func(*args, **kwargs)
return result | python | def cached(func, instance, args, kwargs):
cache = getattr(instance, "__cache", None)
if cache is None:
instance.__cache = cache = {}
try:
return cache[func]
except KeyError:
cache[func] = result = func(*args, **kwargs)
return result | [
"def",
"cached",
"(",
"func",
",",
"instance",
",",
"args",
",",
"kwargs",
")",
":",
"cache",
"=",
"getattr",
"(",
"instance",
",",
"\"__cache\"",
",",
"None",
")",
"if",
"cache",
"is",
"None",
":",
"instance",
".",
"__cache",
"=",
"cache",
"=",
"{",... | Simple decorator to cache result of method calls without args. | [
"Simple",
"decorator",
"to",
"cache",
"result",
"of",
"method",
"calls",
"without",
"args",
"."
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/decorators.py#L25-L34 |
227,177 | PyCQA/astroid | astroid/decorators.py | path_wrapper | 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):
"""wrapper function handling context"""
if context is None:
context = contextmod.InferenceContext()
if context.push(node):
return None
yielded = set()
generator = _func(node, context, **kwargs)
try:
while True:
res = next(generator)
# unproxy only true instance, not const, tuple, dict...
if res.__class__.__name__ == "Instance":
ares = res._proxied
else:
ares = res
if ares not in yielded:
yield res
yielded.add(ares)
except StopIteration as error:
if error.args:
return error.args[0]
return None
return wrapped | python | def path_wrapper(func):
@functools.wraps(func)
def wrapped(node, context=None, _func=func, **kwargs):
"""wrapper function handling context"""
if context is None:
context = contextmod.InferenceContext()
if context.push(node):
return None
yielded = set()
generator = _func(node, context, **kwargs)
try:
while True:
res = next(generator)
# unproxy only true instance, not const, tuple, dict...
if res.__class__.__name__ == "Instance":
ares = res._proxied
else:
ares = res
if ares not in yielded:
yield res
yielded.add(ares)
except StopIteration as error:
if error.args:
return error.args[0]
return None
return wrapped | [
"def",
"path_wrapper",
"(",
"func",
")",
":",
"@",
"functools",
".",
"wraps",
"(",
"func",
")",
"def",
"wrapped",
"(",
"node",
",",
"context",
"=",
"None",
",",
"_func",
"=",
"func",
",",
"*",
"*",
"kwargs",
")",
":",
"\"\"\"wrapper function handling con... | 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 | [
"return",
"the",
"given",
"infer",
"function",
"wrapped",
"to",
"handle",
"the",
"path"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/decorators.py#L76-L109 |
227,178 | PyCQA/astroid | astroid/raw_building.py | attach_dummy_node | 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
"""
enode = nodes.EmptyNode()
enode.object = runtime_object
_attach_local_node(node, enode, name) | python | def attach_dummy_node(node, name, runtime_object=_marker):
enode = nodes.EmptyNode()
enode.object = runtime_object
_attach_local_node(node, enode, name) | [
"def",
"attach_dummy_node",
"(",
"node",
",",
"name",
",",
"runtime_object",
"=",
"_marker",
")",
":",
"enode",
"=",
"nodes",
".",
"EmptyNode",
"(",
")",
"enode",
".",
"object",
"=",
"runtime_object",
"_attach_local_node",
"(",
"node",
",",
"enode",
",",
"... | create a dummy node and register it in the locals of the given
node with the specified name | [
"create",
"a",
"dummy",
"node",
"and",
"register",
"it",
"in",
"the",
"locals",
"of",
"the",
"given",
"node",
"with",
"the",
"specified",
"name"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/raw_building.py#L69-L75 |
227,179 | PyCQA/astroid | astroid/raw_building.py | attach_const_node | 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
"""
if name not in node.special_attributes:
_attach_local_node(node, nodes.const_factory(value), name) | python | def attach_const_node(node, name, value):
if name not in node.special_attributes:
_attach_local_node(node, nodes.const_factory(value), name) | [
"def",
"attach_const_node",
"(",
"node",
",",
"name",
",",
"value",
")",
":",
"if",
"name",
"not",
"in",
"node",
".",
"special_attributes",
":",
"_attach_local_node",
"(",
"node",
",",
"nodes",
".",
"const_factory",
"(",
"value",
")",
",",
"name",
")"
] | create a Const node and register it in the locals of the given
node with the specified name | [
"create",
"a",
"Const",
"node",
"and",
"register",
"it",
"in",
"the",
"locals",
"of",
"the",
"given",
"node",
"with",
"the",
"specified",
"name"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/raw_building.py#L85-L90 |
227,180 | PyCQA/astroid | astroid/raw_building.py | attach_import_node | 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
"""
from_node = nodes.ImportFrom(modname, [(membername, None)])
_attach_local_node(node, from_node, membername) | python | def attach_import_node(node, modname, membername):
from_node = nodes.ImportFrom(modname, [(membername, None)])
_attach_local_node(node, from_node, membername) | [
"def",
"attach_import_node",
"(",
"node",
",",
"modname",
",",
"membername",
")",
":",
"from_node",
"=",
"nodes",
".",
"ImportFrom",
"(",
"modname",
",",
"[",
"(",
"membername",
",",
"None",
")",
"]",
")",
"_attach_local_node",
"(",
"node",
",",
"from_node... | create a ImportFrom node and register it in the locals of the given
node with the specified name | [
"create",
"a",
"ImportFrom",
"node",
"and",
"register",
"it",
"in",
"the",
"locals",
"of",
"the",
"given",
"node",
"with",
"the",
"specified",
"name"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/raw_building.py#L93-L98 |
227,181 | PyCQA/astroid | astroid/raw_building.py | build_module | def build_module(name, doc=None):
"""create and initialize an astroid Module node"""
node = nodes.Module(name, doc, pure_python=False)
node.package = False
node.parent = None
return node | python | def build_module(name, doc=None):
node = nodes.Module(name, doc, pure_python=False)
node.package = False
node.parent = None
return node | [
"def",
"build_module",
"(",
"name",
",",
"doc",
"=",
"None",
")",
":",
"node",
"=",
"nodes",
".",
"Module",
"(",
"name",
",",
"doc",
",",
"pure_python",
"=",
"False",
")",
"node",
".",
"package",
"=",
"False",
"node",
".",
"parent",
"=",
"None",
"r... | create and initialize an astroid Module node | [
"create",
"and",
"initialize",
"an",
"astroid",
"Module",
"node"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/raw_building.py#L101-L106 |
227,182 | PyCQA/astroid | astroid/raw_building.py | build_class | def build_class(name, basenames=(), doc=None):
"""create and initialize an astroid ClassDef node"""
node = nodes.ClassDef(name, doc)
for base in basenames:
basenode = nodes.Name()
basenode.name = base
node.bases.append(basenode)
basenode.parent = node
return node | python | def build_class(name, basenames=(), doc=None):
node = nodes.ClassDef(name, doc)
for base in basenames:
basenode = nodes.Name()
basenode.name = base
node.bases.append(basenode)
basenode.parent = node
return node | [
"def",
"build_class",
"(",
"name",
",",
"basenames",
"=",
"(",
")",
",",
"doc",
"=",
"None",
")",
":",
"node",
"=",
"nodes",
".",
"ClassDef",
"(",
"name",
",",
"doc",
")",
"for",
"base",
"in",
"basenames",
":",
"basenode",
"=",
"nodes",
".",
"Name"... | create and initialize an astroid ClassDef node | [
"create",
"and",
"initialize",
"an",
"astroid",
"ClassDef",
"node"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/raw_building.py#L109-L117 |
227,183 | PyCQA/astroid | astroid/raw_building.py | build_function | 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.args = []
for arg in args:
argsnode.args.append(nodes.Name())
argsnode.args[-1].name = arg
argsnode.args[-1].parent = argsnode
argsnode.defaults = []
for default in defaults:
argsnode.defaults.append(nodes.const_factory(default))
argsnode.defaults[-1].parent = argsnode
argsnode.kwarg = None
argsnode.vararg = None
argsnode.parent = func
if args:
register_arguments(func)
return func | python | def build_function(name, args=None, defaults=None, doc=None):
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.args = []
for arg in args:
argsnode.args.append(nodes.Name())
argsnode.args[-1].name = arg
argsnode.args[-1].parent = argsnode
argsnode.defaults = []
for default in defaults:
argsnode.defaults.append(nodes.const_factory(default))
argsnode.defaults[-1].parent = argsnode
argsnode.kwarg = None
argsnode.vararg = None
argsnode.parent = func
if args:
register_arguments(func)
return func | [
"def",
"build_function",
"(",
"name",
",",
"args",
"=",
"None",
",",
"defaults",
"=",
"None",
",",
"doc",
"=",
"None",
")",
":",
"args",
",",
"defaults",
"=",
"args",
"or",
"[",
"]",
",",
"defaults",
"or",
"[",
"]",
"# first argument is now a list of dec... | create and initialize an astroid FunctionDef node | [
"create",
"and",
"initialize",
"an",
"astroid",
"FunctionDef",
"node"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/raw_building.py#L120-L140 |
227,184 | PyCQA/astroid | astroid/raw_building.py | register_arguments | 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)
if func.args.kwarg:
func.set_local(func.args.kwarg, func.args)
for arg in args:
if isinstance(arg, nodes.Name):
func.set_local(arg.name, arg)
else:
register_arguments(func, arg.elts) | python | def register_arguments(func, args=None):
if args is None:
args = func.args.args
if func.args.vararg:
func.set_local(func.args.vararg, func.args)
if func.args.kwarg:
func.set_local(func.args.kwarg, func.args)
for arg in args:
if isinstance(arg, nodes.Name):
func.set_local(arg.name, arg)
else:
register_arguments(func, arg.elts) | [
"def",
"register_arguments",
"(",
"func",
",",
"args",
"=",
"None",
")",
":",
"if",
"args",
"is",
"None",
":",
"args",
"=",
"func",
".",
"args",
".",
"args",
"if",
"func",
".",
"args",
".",
"vararg",
":",
"func",
".",
"set_local",
"(",
"func",
".",... | add given arguments to local
args is a list that may contains nested lists
(i.e. def func(a, (b, c, d)): ...) | [
"add",
"given",
"arguments",
"to",
"local"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/raw_building.py#L148-L164 |
227,185 | PyCQA/astroid | astroid/raw_building.py | object_build_class | def object_build_class(node, member, localname):
"""create astroid for a living class object"""
basenames = [base.__name__ for base in member.__bases__]
return _base_class_object_build(node, member, basenames, localname=localname) | python | def object_build_class(node, member, localname):
basenames = [base.__name__ for base in member.__bases__]
return _base_class_object_build(node, member, basenames, localname=localname) | [
"def",
"object_build_class",
"(",
"node",
",",
"member",
",",
"localname",
")",
":",
"basenames",
"=",
"[",
"base",
".",
"__name__",
"for",
"base",
"in",
"member",
".",
"__bases__",
"]",
"return",
"_base_class_object_build",
"(",
"node",
",",
"member",
",",
... | create astroid for a living class object | [
"create",
"astroid",
"for",
"a",
"living",
"class",
"object"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/raw_building.py#L167-L170 |
227,186 | PyCQA/astroid | astroid/raw_building.py | object_build_function | 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:
args.append(varkw)
func = build_function(
getattr(member, "__name__", None) or localname, args, defaults, member.__doc__
)
node.add_local_node(func, localname) | python | def object_build_function(node, member, localname):
# 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:
args.append(varkw)
func = build_function(
getattr(member, "__name__", None) or localname, args, defaults, member.__doc__
)
node.add_local_node(func, localname) | [
"def",
"object_build_function",
"(",
"node",
",",
"member",
",",
"localname",
")",
":",
"# pylint: disable=deprecated-method; completely removed in 2.0",
"args",
",",
"varargs",
",",
"varkw",
",",
"defaults",
"=",
"inspect",
".",
"getargspec",
"(",
"member",
")",
"i... | create astroid for a living function object | [
"create",
"astroid",
"for",
"a",
"living",
"function",
"object"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/raw_building.py#L173-L184 |
227,187 | PyCQA/astroid | astroid/raw_building.py | object_build_methoddescriptor | 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 to None to notice that we have no information, not
# and empty argument list
func.args.args = None
node.add_local_node(func, localname)
_add_dunder_class(func, member) | python | def object_build_methoddescriptor(node, member, localname):
# FIXME get arguments ?
func = build_function(
getattr(member, "__name__", None) or localname, doc=member.__doc__
)
# set node's arguments to None to notice that we have no information, not
# and empty argument list
func.args.args = None
node.add_local_node(func, localname)
_add_dunder_class(func, member) | [
"def",
"object_build_methoddescriptor",
"(",
"node",
",",
"member",
",",
"localname",
")",
":",
"# FIXME get arguments ?",
"func",
"=",
"build_function",
"(",
"getattr",
"(",
"member",
",",
"\"__name__\"",
",",
"None",
")",
"or",
"localname",
",",
"doc",
"=",
... | create astroid for a living method descriptor object | [
"create",
"astroid",
"for",
"a",
"living",
"method",
"descriptor",
"object"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/raw_building.py#L192-L202 |
227,188 | PyCQA/astroid | astroid/raw_building.py | _astroid_bootstrapping | 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=redefined-outer-name
for cls, node_cls in node_classes.CONST_CLS.items():
if cls is type(None):
proxy = build_class("NoneType")
proxy.parent = astroid_builtin
elif cls is type(NotImplemented):
proxy = build_class("NotImplementedType")
proxy.parent = astroid_builtin
else:
proxy = astroid_builtin.getattr(cls.__name__)[0]
if cls in (dict, list, set, tuple):
node_cls._proxied = proxy
else:
_CONST_PROXY[cls] = proxy
# Set the builtin module as parent for some builtins.
nodes.Const._proxied = property(_set_proxied)
_GeneratorType = nodes.ClassDef(
types.GeneratorType.__name__, types.GeneratorType.__doc__
)
_GeneratorType.parent = astroid_builtin
bases.Generator._proxied = _GeneratorType
builder.object_build(bases.Generator._proxied, types.GeneratorType)
if hasattr(types, "AsyncGeneratorType"):
# pylint: disable=no-member; AsyncGeneratorType
_AsyncGeneratorType = nodes.ClassDef(
types.AsyncGeneratorType.__name__, types.AsyncGeneratorType.__doc__
)
_AsyncGeneratorType.parent = astroid_builtin
bases.AsyncGenerator._proxied = _AsyncGeneratorType
builder.object_build(bases.AsyncGenerator._proxied, types.AsyncGeneratorType)
builtin_types = (
types.GetSetDescriptorType,
types.GeneratorType,
types.MemberDescriptorType,
type(None),
type(NotImplemented),
types.FunctionType,
types.MethodType,
types.BuiltinFunctionType,
types.ModuleType,
types.TracebackType,
)
for _type in builtin_types:
if _type.__name__ not in astroid_builtin:
cls = nodes.ClassDef(_type.__name__, _type.__doc__)
cls.parent = astroid_builtin
builder.object_build(cls, _type)
astroid_builtin[_type.__name__] = cls | python | def _astroid_bootstrapping():
# 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=redefined-outer-name
for cls, node_cls in node_classes.CONST_CLS.items():
if cls is type(None):
proxy = build_class("NoneType")
proxy.parent = astroid_builtin
elif cls is type(NotImplemented):
proxy = build_class("NotImplementedType")
proxy.parent = astroid_builtin
else:
proxy = astroid_builtin.getattr(cls.__name__)[0]
if cls in (dict, list, set, tuple):
node_cls._proxied = proxy
else:
_CONST_PROXY[cls] = proxy
# Set the builtin module as parent for some builtins.
nodes.Const._proxied = property(_set_proxied)
_GeneratorType = nodes.ClassDef(
types.GeneratorType.__name__, types.GeneratorType.__doc__
)
_GeneratorType.parent = astroid_builtin
bases.Generator._proxied = _GeneratorType
builder.object_build(bases.Generator._proxied, types.GeneratorType)
if hasattr(types, "AsyncGeneratorType"):
# pylint: disable=no-member; AsyncGeneratorType
_AsyncGeneratorType = nodes.ClassDef(
types.AsyncGeneratorType.__name__, types.AsyncGeneratorType.__doc__
)
_AsyncGeneratorType.parent = astroid_builtin
bases.AsyncGenerator._proxied = _AsyncGeneratorType
builder.object_build(bases.AsyncGenerator._proxied, types.AsyncGeneratorType)
builtin_types = (
types.GetSetDescriptorType,
types.GeneratorType,
types.MemberDescriptorType,
type(None),
type(NotImplemented),
types.FunctionType,
types.MethodType,
types.BuiltinFunctionType,
types.ModuleType,
types.TracebackType,
)
for _type in builtin_types:
if _type.__name__ not in astroid_builtin:
cls = nodes.ClassDef(_type.__name__, _type.__doc__)
cls.parent = astroid_builtin
builder.object_build(cls, _type)
astroid_builtin[_type.__name__] = cls | [
"def",
"_astroid_bootstrapping",
"(",
")",
":",
"# 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",
"(",
... | astroid bootstrapping the builtins module | [
"astroid",
"bootstrapping",
"the",
"builtins",
"module"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/raw_building.py#L384-L441 |
227,189 | PyCQA/astroid | astroid/raw_building.py | InspectBuilder.imported_member | 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 instance)
try:
modname = getattr(member, "__module__", None)
except TypeError:
modname = None
if modname is None:
if name in ("__new__", "__subclasshook__"):
# Python 2.5.1 (r251:54863, Sep 1 2010, 22:03:14)
# >>> print object.__new__.__module__
# None
modname = builtins.__name__
else:
attach_dummy_node(node, name, member)
return True
real_name = {"gtk": "gtk_gtk", "_io": "io"}.get(modname, modname)
if real_name != self._module.__name__:
# check if it sounds valid and then add an import node, else use a
# dummy node
try:
getattr(sys.modules[modname], name)
except (KeyError, AttributeError):
attach_dummy_node(node, name, member)
else:
attach_import_node(node, modname, name)
return True
return False | python | def imported_member(self, node, member, name):
# /!\ 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 instance)
try:
modname = getattr(member, "__module__", None)
except TypeError:
modname = None
if modname is None:
if name in ("__new__", "__subclasshook__"):
# Python 2.5.1 (r251:54863, Sep 1 2010, 22:03:14)
# >>> print object.__new__.__module__
# None
modname = builtins.__name__
else:
attach_dummy_node(node, name, member)
return True
real_name = {"gtk": "gtk_gtk", "_io": "io"}.get(modname, modname)
if real_name != self._module.__name__:
# check if it sounds valid and then add an import node, else use a
# dummy node
try:
getattr(sys.modules[modname], name)
except (KeyError, AttributeError):
attach_dummy_node(node, name, member)
else:
attach_import_node(node, modname, name)
return True
return False | [
"def",
"imported_member",
"(",
"self",
",",
"node",
",",
"member",
",",
"name",
")",
":",
"# /!\\ 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 instan... | verify this is not an imported class or handle it | [
"verify",
"this",
"is",
"not",
"an",
"imported",
"class",
"or",
"handle",
"it"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/raw_building.py#L341-L372 |
227,190 | PyCQA/astroid | astroid/builder.py | parse | 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_transforms:
Apply the transforms for the give code. Use it if you
don't want the default transforms to be applied.
"""
code = textwrap.dedent(code)
builder = AstroidBuilder(manager=MANAGER, apply_transforms=apply_transforms)
return builder.string_build(code, modname=module_name, path=path) | python | def parse(code, module_name="", path=None, apply_transforms=True):
code = textwrap.dedent(code)
builder = AstroidBuilder(manager=MANAGER, apply_transforms=apply_transforms)
return builder.string_build(code, modname=module_name, path=path) | [
"def",
"parse",
"(",
"code",
",",
"module_name",
"=",
"\"\"",
",",
"path",
"=",
"None",
",",
"apply_transforms",
"=",
"True",
")",
":",
"code",
"=",
"textwrap",
".",
"dedent",
"(",
"code",
")",
"builder",
"=",
"AstroidBuilder",
"(",
"manager",
"=",
"MA... | 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_transforms:
Apply the transforms for the give code. Use it if you
don't want the default transforms to be applied. | [
"Parses",
"a",
"source",
"string",
"in",
"order",
"to",
"obtain",
"an",
"astroid",
"AST",
"from",
"it"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/builder.py#L263-L275 |
227,191 | PyCQA/astroid | astroid/builder.py | _extract_expressions | 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 the tree,
replacing it by the wrapped expression inside the parent.
:param node: An astroid node.
:type node: astroid.bases.NodeNG
:yields: The sequence of wrapped expressions on the modified tree
expression can be found.
"""
if (
isinstance(node, nodes.Call)
and isinstance(node.func, nodes.Name)
and node.func.name == _TRANSIENT_FUNCTION
):
real_expr = node.args[0]
real_expr.parent = node.parent
# Search for node in all _astng_fields (the fields checked when
# get_children is called) of its parent. Some of those fields may
# be lists or tuples, in which case the elements need to be checked.
# When we find it, replace it by real_expr, so that the AST looks
# like no call to _TRANSIENT_FUNCTION ever took place.
for name in node.parent._astroid_fields:
child = getattr(node.parent, name)
if isinstance(child, (list, tuple)):
for idx, compound_child in enumerate(child):
if compound_child is node:
child[idx] = real_expr
elif child is node:
setattr(node.parent, name, real_expr)
yield real_expr
else:
for child in node.get_children():
yield from _extract_expressions(child) | python | def _extract_expressions(node):
if (
isinstance(node, nodes.Call)
and isinstance(node.func, nodes.Name)
and node.func.name == _TRANSIENT_FUNCTION
):
real_expr = node.args[0]
real_expr.parent = node.parent
# Search for node in all _astng_fields (the fields checked when
# get_children is called) of its parent. Some of those fields may
# be lists or tuples, in which case the elements need to be checked.
# When we find it, replace it by real_expr, so that the AST looks
# like no call to _TRANSIENT_FUNCTION ever took place.
for name in node.parent._astroid_fields:
child = getattr(node.parent, name)
if isinstance(child, (list, tuple)):
for idx, compound_child in enumerate(child):
if compound_child is node:
child[idx] = real_expr
elif child is node:
setattr(node.parent, name, real_expr)
yield real_expr
else:
for child in node.get_children():
yield from _extract_expressions(child) | [
"def",
"_extract_expressions",
"(",
"node",
")",
":",
"if",
"(",
"isinstance",
"(",
"node",
",",
"nodes",
".",
"Call",
")",
"and",
"isinstance",
"(",
"node",
".",
"func",
",",
"nodes",
".",
"Name",
")",
"and",
"node",
".",
"func",
".",
"name",
"==",
... | 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 the tree,
replacing it by the wrapped expression inside the parent.
:param node: An astroid node.
:type node: astroid.bases.NodeNG
:yields: The sequence of wrapped expressions on the modified tree
expression can be found. | [
"Find",
"expressions",
"in",
"a",
"call",
"to",
"_TRANSIENT_FUNCTION",
"and",
"extract",
"them",
"."
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/builder.py#L278-L314 |
227,192 | PyCQA/astroid | astroid/builder.py | _find_statement_by_line | 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.NodeNG
:param line: The line number of the statement to extract.
:type line: int
:returns: The statement on the line, or None if no statement for the line
can be found.
:rtype: astroid.bases.NodeNG or None
"""
if isinstance(node, (nodes.ClassDef, nodes.FunctionDef)):
# This is an inaccuracy in the AST: the nodes that can be
# decorated do not carry explicit information on which line
# the actual definition (class/def), but .fromline seems to
# be close enough.
node_line = node.fromlineno
else:
node_line = node.lineno
if node_line == line:
return node
for child in node.get_children():
result = _find_statement_by_line(child, line)
if result:
return result
return None | python | def _find_statement_by_line(node, line):
if isinstance(node, (nodes.ClassDef, nodes.FunctionDef)):
# This is an inaccuracy in the AST: the nodes that can be
# decorated do not carry explicit information on which line
# the actual definition (class/def), but .fromline seems to
# be close enough.
node_line = node.fromlineno
else:
node_line = node.lineno
if node_line == line:
return node
for child in node.get_children():
result = _find_statement_by_line(child, line)
if result:
return result
return None | [
"def",
"_find_statement_by_line",
"(",
"node",
",",
"line",
")",
":",
"if",
"isinstance",
"(",
"node",
",",
"(",
"nodes",
".",
"ClassDef",
",",
"nodes",
".",
"FunctionDef",
")",
")",
":",
"# This is an inaccuracy in the AST: the nodes that can be",
"# decorated do n... | 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.NodeNG
:param line: The line number of the statement to extract.
:type line: int
:returns: The statement on the line, or None if no statement for the line
can be found.
:rtype: astroid.bases.NodeNG or None | [
"Extracts",
"the",
"statement",
"on",
"a",
"specific",
"line",
"from",
"an",
"AST",
"."
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/builder.py#L317-L349 |
227,193 | PyCQA/astroid | astroid/builder.py | extract_node | 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 statement will be extracted.
>>> class X(object):
>>> def meth(self): #@
>>> pass
The function object 'meth' will be extracted.
Expressions:
To extract arbitrary expressions, surround them with the fake
function call __(...). After parsing, the surrounded expression
will be returned and the whole AST (accessible via the returned
node's parent attribute) will look like the function call was
never there in the first place.
Examples:
>>> a = __(1)
The const node will be extracted.
>>> def x(d=__(foo.bar)): pass
The node containing the default argument will be extracted.
>>> def foo(a, b):
>>> return 0 < __(len(a)) < b
The node containing the function call 'len' will be extracted.
If no statements or expressions are selected, the last toplevel
statement will be returned.
If the selected statement is a discard statement, (i.e. an expression
turned into a statement), the wrapped expression is returned instead.
For convenience, singleton lists are unpacked.
:param str code: A piece of Python code that is parsed as
a module. Will be passed through textwrap.dedent first.
:param str module_name: The name of the module.
:returns: The designated node from the parse tree, or a list of nodes.
:rtype: astroid.bases.NodeNG, or a list of nodes.
"""
def _extract(node):
if isinstance(node, nodes.Expr):
return node.value
return node
requested_lines = []
for idx, line in enumerate(code.splitlines()):
if line.strip().endswith(_STATEMENT_SELECTOR):
requested_lines.append(idx + 1)
tree = parse(code, module_name=module_name)
if not tree.body:
raise ValueError("Empty tree, cannot extract from it")
extracted = []
if requested_lines:
extracted = [_find_statement_by_line(tree, line) for line in requested_lines]
# Modifies the tree.
extracted.extend(_extract_expressions(tree))
if not extracted:
extracted.append(tree.body[-1])
extracted = [_extract(node) for node in extracted]
if len(extracted) == 1:
return extracted[0]
return extracted | python | def extract_node(code, module_name=""):
def _extract(node):
if isinstance(node, nodes.Expr):
return node.value
return node
requested_lines = []
for idx, line in enumerate(code.splitlines()):
if line.strip().endswith(_STATEMENT_SELECTOR):
requested_lines.append(idx + 1)
tree = parse(code, module_name=module_name)
if not tree.body:
raise ValueError("Empty tree, cannot extract from it")
extracted = []
if requested_lines:
extracted = [_find_statement_by_line(tree, line) for line in requested_lines]
# Modifies the tree.
extracted.extend(_extract_expressions(tree))
if not extracted:
extracted.append(tree.body[-1])
extracted = [_extract(node) for node in extracted]
if len(extracted) == 1:
return extracted[0]
return extracted | [
"def",
"extract_node",
"(",
"code",
",",
"module_name",
"=",
"\"\"",
")",
":",
"def",
"_extract",
"(",
"node",
")",
":",
"if",
"isinstance",
"(",
"node",
",",
"nodes",
".",
"Expr",
")",
":",
"return",
"node",
".",
"value",
"return",
"node",
"requested_... | 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 statement will be extracted.
>>> class X(object):
>>> def meth(self): #@
>>> pass
The function object 'meth' will be extracted.
Expressions:
To extract arbitrary expressions, surround them with the fake
function call __(...). After parsing, the surrounded expression
will be returned and the whole AST (accessible via the returned
node's parent attribute) will look like the function call was
never there in the first place.
Examples:
>>> a = __(1)
The const node will be extracted.
>>> def x(d=__(foo.bar)): pass
The node containing the default argument will be extracted.
>>> def foo(a, b):
>>> return 0 < __(len(a)) < b
The node containing the function call 'len' will be extracted.
If no statements or expressions are selected, the last toplevel
statement will be returned.
If the selected statement is a discard statement, (i.e. an expression
turned into a statement), the wrapped expression is returned instead.
For convenience, singleton lists are unpacked.
:param str code: A piece of Python code that is parsed as
a module. Will be passed through textwrap.dedent first.
:param str module_name: The name of the module.
:returns: The designated node from the parse tree, or a list of nodes.
:rtype: astroid.bases.NodeNG, or a list of nodes. | [
"Parses",
"some",
"Python",
"code",
"as",
"a",
"module",
"and",
"extracts",
"a",
"designated",
"AST",
"node",
"."
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/builder.py#L352-L435 |
227,194 | PyCQA/astroid | astroid/builder.py | AstroidBuilder.module_build | 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", ".pyo") and os.path.exists(path_ + ".py"):
node = self.file_build(path_ + ".py", modname)
if node is None:
# this is a built-in module
# get a partial representation by introspection
node = self.inspect_build(module, modname=modname, path=path)
if self._apply_transforms:
# We have to handle transformation by ourselves since the
# rebuilder isn't called for builtin nodes
node = self._manager.visit_transforms(node)
return node | python | def module_build(self, module, modname=None):
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", ".pyo") and os.path.exists(path_ + ".py"):
node = self.file_build(path_ + ".py", modname)
if node is None:
# this is a built-in module
# get a partial representation by introspection
node = self.inspect_build(module, modname=modname, path=path)
if self._apply_transforms:
# We have to handle transformation by ourselves since the
# rebuilder isn't called for builtin nodes
node = self._manager.visit_transforms(node)
return node | [
"def",
"module_build",
"(",
"self",
",",
"module",
",",
"modname",
"=",
"None",
")",
":",
"node",
"=",
"None",
"path",
"=",
"getattr",
"(",
"module",
",",
"\"__file__\"",
",",
"None",
")",
"if",
"path",
"is",
"not",
"None",
":",
"path_",
",",
"ext",
... | Build an astroid from a living module instance. | [
"Build",
"an",
"astroid",
"from",
"a",
"living",
"module",
"instance",
"."
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/builder.py#L82-L98 |
227,195 | PyCQA/astroid | astroid/builder.py | AstroidBuilder.string_build | def string_build(self, data, modname="", path=None):
"""Build astroid from source code string."""
module = self._data_build(data, modname, path)
module.file_bytes = data.encode("utf-8")
return self._post_build(module, "utf-8") | python | def string_build(self, data, modname="", path=None):
module = self._data_build(data, modname, path)
module.file_bytes = data.encode("utf-8")
return self._post_build(module, "utf-8") | [
"def",
"string_build",
"(",
"self",
",",
"data",
",",
"modname",
"=",
"\"\"",
",",
"path",
"=",
"None",
")",
":",
"module",
"=",
"self",
".",
"_data_build",
"(",
"data",
",",
"modname",
",",
"path",
")",
"module",
".",
"file_bytes",
"=",
"data",
".",... | Build astroid from source code string. | [
"Build",
"astroid",
"from",
"source",
"code",
"string",
"."
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/builder.py#L138-L142 |
227,196 | PyCQA/astroid | astroid/builder.py | AstroidBuilder._post_build | 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_from_nodes:
if from_node.modname == "__future__":
for symbol, _ in from_node.names:
module.future_imports.add(symbol)
self.add_from_names_to_locals(from_node)
# handle delayed assattr nodes
for delayed in module._delayed_assattr:
self.delayed_assattr(delayed)
# Visit the transforms
if self._apply_transforms:
module = self._manager.visit_transforms(module)
return module | python | def _post_build(self, module, encoding):
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_from_nodes:
if from_node.modname == "__future__":
for symbol, _ in from_node.names:
module.future_imports.add(symbol)
self.add_from_names_to_locals(from_node)
# handle delayed assattr nodes
for delayed in module._delayed_assattr:
self.delayed_assattr(delayed)
# Visit the transforms
if self._apply_transforms:
module = self._manager.visit_transforms(module)
return module | [
"def",
"_post_build",
"(",
"self",
",",
"module",
",",
"encoding",
")",
":",
"module",
".",
"file_encoding",
"=",
"encoding",
"self",
".",
"_manager",
".",
"cache_module",
"(",
"module",
")",
"# post tree building steps after we stored the module in the cache:",
"for"... | Handles encoding and delayed nodes after a module has been built | [
"Handles",
"encoding",
"and",
"delayed",
"nodes",
"after",
"a",
"module",
"has",
"been",
"built"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/builder.py#L144-L161 |
227,197 | PyCQA/astroid | astroid/builder.py | AstroidBuilder._data_build | 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{error}",
source=data,
modname=modname,
path=path,
error=exc,
) from exc
if path is not None:
node_file = os.path.abspath(path)
else:
node_file = "<?>"
if modname.endswith(".__init__"):
modname = modname[:-9]
package = True
else:
package = (
path is not None
and os.path.splitext(os.path.basename(path))[0] == "__init__"
)
builder = rebuilder.TreeRebuilder(self._manager)
module = builder.visit_module(node, modname, node_file, package)
module._import_from_nodes = builder._import_from_nodes
module._delayed_assattr = builder._delayed_assattr
return module | python | def _data_build(self, data, modname, path):
try:
node = _parse(data + "\n")
except (TypeError, ValueError, SyntaxError) as exc:
raise exceptions.AstroidSyntaxError(
"Parsing Python code failed:\n{error}",
source=data,
modname=modname,
path=path,
error=exc,
) from exc
if path is not None:
node_file = os.path.abspath(path)
else:
node_file = "<?>"
if modname.endswith(".__init__"):
modname = modname[:-9]
package = True
else:
package = (
path is not None
and os.path.splitext(os.path.basename(path))[0] == "__init__"
)
builder = rebuilder.TreeRebuilder(self._manager)
module = builder.visit_module(node, modname, node_file, package)
module._import_from_nodes = builder._import_from_nodes
module._delayed_assattr = builder._delayed_assattr
return module | [
"def",
"_data_build",
"(",
"self",
",",
"data",
",",
"modname",
",",
"path",
")",
":",
"try",
":",
"node",
"=",
"_parse",
"(",
"data",
"+",
"\"\\n\"",
")",
"except",
"(",
"TypeError",
",",
"ValueError",
",",
"SyntaxError",
")",
"as",
"exc",
":",
"rai... | Build tree node from data and add some informations | [
"Build",
"tree",
"node",
"from",
"data",
"and",
"add",
"some",
"informations"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/builder.py#L163-L191 |
227,198 | PyCQA/astroid | astroid/builder.py | AstroidBuilder.add_from_names_to_locals | 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.names:
if name == "*":
try:
imported = node.do_import_module()
except exceptions.AstroidBuildingError:
continue
for name in imported.public_names():
node.parent.set_local(name, node)
sort_locals(node.parent.scope().locals[name])
else:
node.parent.set_local(asname or name, node)
sort_locals(node.parent.scope().locals[asname or name]) | python | def add_from_names_to_locals(self, node):
_key_func = lambda node: node.fromlineno
def sort_locals(my_list):
my_list.sort(key=_key_func)
for (name, asname) in node.names:
if name == "*":
try:
imported = node.do_import_module()
except exceptions.AstroidBuildingError:
continue
for name in imported.public_names():
node.parent.set_local(name, node)
sort_locals(node.parent.scope().locals[name])
else:
node.parent.set_local(asname or name, node)
sort_locals(node.parent.scope().locals[asname or name]) | [
"def",
"add_from_names_to_locals",
"(",
"self",
",",
"node",
")",
":",
"_key_func",
"=",
"lambda",
"node",
":",
"node",
".",
"fromlineno",
"def",
"sort_locals",
"(",
"my_list",
")",
":",
"my_list",
".",
"sort",
"(",
"key",
"=",
"_key_func",
")",
"for",
"... | Store imported names to the locals
Resort the locals if coming from a delayed node | [
"Store",
"imported",
"names",
"to",
"the",
"locals"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/builder.py#L193-L214 |
227,199 | PyCQA/astroid | astroid/builder.py | AstroidBuilder.delayed_assattr | 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
try:
if inferred.__class__ is bases.Instance:
inferred = inferred._proxied
iattrs = inferred.instance_attrs
if not _can_assign_attr(inferred, node.attrname):
continue
elif isinstance(inferred, bases.Instance):
# Const, Tuple, ... we may be wrong, may be not, but
# anyway we don't want to pollute builtin's namespace
continue
elif inferred.is_function:
iattrs = inferred.instance_attrs
else:
iattrs = inferred.locals
except AttributeError:
# XXX log error
continue
values = iattrs.setdefault(node.attrname, [])
if node in values:
continue
# get assign in __init__ first XXX useful ?
if (
frame.name == "__init__"
and values
and values[0].frame().name != "__init__"
):
values.insert(0, node)
else:
values.append(node)
except exceptions.InferenceError:
pass | python | def delayed_assattr(self, node):
try:
frame = node.frame()
for inferred in node.expr.infer():
if inferred is util.Uninferable:
continue
try:
if inferred.__class__ is bases.Instance:
inferred = inferred._proxied
iattrs = inferred.instance_attrs
if not _can_assign_attr(inferred, node.attrname):
continue
elif isinstance(inferred, bases.Instance):
# Const, Tuple, ... we may be wrong, may be not, but
# anyway we don't want to pollute builtin's namespace
continue
elif inferred.is_function:
iattrs = inferred.instance_attrs
else:
iattrs = inferred.locals
except AttributeError:
# XXX log error
continue
values = iattrs.setdefault(node.attrname, [])
if node in values:
continue
# get assign in __init__ first XXX useful ?
if (
frame.name == "__init__"
and values
and values[0].frame().name != "__init__"
):
values.insert(0, node)
else:
values.append(node)
except exceptions.InferenceError:
pass | [
"def",
"delayed_assattr",
"(",
"self",
",",
"node",
")",
":",
"try",
":",
"frame",
"=",
"node",
".",
"frame",
"(",
")",
"for",
"inferred",
"in",
"node",
".",
"expr",
".",
"infer",
"(",
")",
":",
"if",
"inferred",
"is",
"util",
".",
"Uninferable",
"... | Visit a AssAttr node
This adds name to locals and handle members definition. | [
"Visit",
"a",
"AssAttr",
"node"
] | e0a298df55b15abcb77c2a93253f5ab7be52d0fb | https://github.com/PyCQA/astroid/blob/e0a298df55b15abcb77c2a93253f5ab7be52d0fb/astroid/builder.py#L216-L256 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.