_id stringlengths 2 7 | title stringlengths 1 88 | partition stringclasses 3
values | text stringlengths 31 13.1k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q31000 | are_exclusive | train | def are_exclusive(
stmt1, stmt2, exceptions=None
): # pylint: disable=redefined-outer-name
"""return true if the two given statements are mutually exclusive
`exceptions` may be a list of exception names. If specified, discard If
branches and check one of the statement is in an exception handler catchi... | python | {
"resource": ""
} |
q31001 | _slice_value | train | def _slice_value(index, context=None):
"""Get the value of the given slice index."""
if isinstance(index, Const):
if isinstance(index.value, (int, type(None))):
return index.value
elif index is None:
return None
else:
# Try to infer what the index actually is.
... | python | {
"resource": ""
} |
q31002 | _update_const_classes | train | def _update_const_classes():
"""update constant classes, so the keys of CONST_CLS can be reused"""
klasses = | python | {
"resource": ""
} |
q31003 | const_factory | train | def const_factory(value):
"""return an astroid node for a python value"""
# XXX we should probably be stricter here and only consider stuff in
# CONST_CLS or do better treatment: in case where value is not in CONST_CLS,
# we should rather recall the builder on this value than returning an empty
# no... | python | {
"resource": ""
} |
q31004 | is_from_decorator | train | def is_from_decorator(node):
"""Return True if the given node is the child of a decorator"""
parent = node.parent
while parent is not None:
| python | {
"resource": ""
} |
q31005 | NodeNG.infer | train | def infer(self, context=None, **kwargs):
"""Get a generator of the inferred values.
This is the main entry point to the inference system.
.. seealso:: :ref:`inference`
If the instance has some explicit inference function set, it will be
called instead of the default interface.... | python | {
"resource": ""
} |
q31006 | NodeNG._repr_name | train | def _repr_name(self):
"""Get a name for nice representation.
This is either :attr:`name`, :attr:`attrname`, or the empty string.
:returns: The nice name.
:rtype: str
"""
names = {"name", "attrname"}
| python | {
"resource": ""
} |
q31007 | NodeNG.accept | train | def accept(self, visitor):
"""Visit this node using the given visitor."""
func | python | {
"resource": ""
} |
q31008 | NodeNG.parent_of | train | def parent_of(self, node):
"""Check if this node is the parent of the given node.
:param node: The node to check if it is the child.
:type node: NodeNG
:returns: True if this node is the parent of the given node,
False otherwise.
:rtype: bool
| python | {
"resource": ""
} |
q31009 | NodeNG.child_sequence | train | def child_sequence(self, child):
"""Search for the sequence that contains this child.
:param child: The child node to search sequences for.
:type child: NodeNG
:returns: The sequence containing the given child node.
:rtype: iterable(NodeNG)
:raises AstroidError: If no ... | python | {
"resource": ""
} |
q31010 | NodeNG.nearest | train | def nearest(self, nodes):
"""Get the node closest to this one from the given list of nodes.
:param nodes: The list of nodes to search. All of these nodes must
belong to the same module as this one. The list should be
sorted by the line number of the nodes, smallest first.
... | python | {
"resource": ""
} |
q31011 | NodeNG.tolineno | train | def tolineno(self):
"""The last line that this node appears on in the source code.
:type: int or None
"""
if not self._astroid_fields:
# can't have children
lastchild = None
| python | {
"resource": ""
} |
q31012 | NodeNG._fixed_source_line | train | def _fixed_source_line(self):
"""Attempt to find the line that this node appears on.
We need this method since not all nodes have :attr:`lineno` set.
:returns: The line number of this node,
or None if this could not be determined.
:rtype: int or None
"""
lin... | python | {
"resource": ""
} |
q31013 | Statement.next_sibling | train | def next_sibling(self):
"""The next sibling statement node.
:returns: The next sibling statement node.
:rtype: NodeNG or | python | {
"resource": ""
} |
q31014 | Statement.previous_sibling | train | def previous_sibling(self):
"""The previous sibling statement.
:returns: The previous sibling statement node.
| python | {
"resource": ""
} |
q31015 | _BaseContainer.from_elements | train | def from_elements(cls, elts=None):
"""Create a node of this type from the given list of elements.
:param elts: The list of elements that the node should contain.
:type elts: list(NodeNG)
:returns: A new node containing the given elements.
:rtype: NodeNG
| python | {
"resource": ""
} |
q31016 | LookupMixIn.ilookup | train | def ilookup(self, name):
"""Lookup the inferred values of the given variable.
:param name: The variable name to find values for.
:type name: str
:returns: The inferred values of the statements returned from
:meth:`lookup`.
:rtype: iterable
| python | {
"resource": ""
} |
q31017 | LookupMixIn._filter_stmts | train | def _filter_stmts(self, stmts, frame, offset):
"""Filter the given list of statements to remove ignorable statements.
If self is not a frame itself and the name is found in the inner
frame locals, statements will be filtered to remove ignorable
statements according to self's location.
... | python | {
"resource": ""
} |
q31018 | Arguments.format_args | train | def format_args(self):
"""Get the arguments formatted as string.
:returns: The formatted arguments.
:rtype: str
"""
result = []
if self.args:
result.append(
_format_args(
self.args, self.defaults, getattr(self, "annotations... | python | {
"resource": ""
} |
q31019 | Arguments.default_value | train | def default_value(self, argname):
"""Get the default value for an argument.
:param argname: The name of the argument to get the default value for.
:type argname: str
:raises NoDefault: If there is no default value defined for the
given argument.
"""
i = _fin... | python | {
"resource": ""
} |
q31020 | Arguments.is_argument | train | def is_argument(self, name):
"""Check if the given name is defined in the arguments.
:param name: The name to check for.
:type name: str
:returns: True if the given name is defined in the arguments,
False otherwise.
:rtype: bool
"""
if name == self.v... | python | {
"resource": ""
} |
q31021 | Call.starargs | train | def starargs(self):
"""The positional arguments that unpack something.
:type: list(Starred)
"""
| python | {
"resource": ""
} |
q31022 | Call.kwargs | train | def kwargs(self):
"""The keyword arguments that unpack something.
:type: list(Keyword)
"""
keywords | python | {
"resource": ""
} |
q31023 | Const.getitem | train | def getitem(self, index, context=None):
"""Get an item from this node if subscriptable.
:param index: The node to use as a subscript index.
:type index: Const or Slice
:raises AstroidTypeError: When the given index cannot be used as a
subscript index, or if this node is not... | python | {
"resource": ""
} |
q31024 | ExceptHandler.blockstart_tolineno | train | def blockstart_tolineno(self):
"""The line on which the beginning of this block ends.
:type: int
"""
if self.name:
return self.name.tolineno
| python | {
"resource": ""
} |
q31025 | ExceptHandler.catch | train | def catch(self, exceptions): # pylint: disable=redefined-outer-name
"""Check if this node handles any of the given exceptions.
If ``exceptions`` is empty, this will default to ``True``.
:param exceptions: The name of the exceptions to check for.
:type exceptions: list(str)
"""... | python | {
"resource": ""
} |
q31026 | Slice._wrap_attribute | train | def _wrap_attribute(self, attr):
"""Wrap the empty attributes of the Slice in a Const node."""
| python | {
"resource": ""
} |
q31027 | Slice.igetattr | train | def igetattr(self, attrname, context=None):
"""Infer the possible values of the given attribute on the slice.
:param attrname: The name of the attribute to infer.
:type attrname: str
:returns: The inferred possible values.
| python | {
"resource": ""
} |
q31028 | _gi_build_stub | train | def _gi_build_stub(parent):
"""
Inspect the passed module recursively and build stubs for functions,
classes, etc.
"""
classes = {}
functions = {}
constants = {}
methods = {}
for name in dir(parent):
if name.startswith("__"):
continue
# Check if this is a... | python | {
"resource": ""
} |
q31029 | object_type | train | def object_type(node, context=None):
"""Obtain the type of the given node
This is used to implement the ``type`` builtin, which means that it's
used for inferring type calls, as well as used in a couple of other places
in the inference.
The node will be inferred first, so this function can support ... | python | {
"resource": ""
} |
q31030 | object_isinstance | train | def object_isinstance(node, class_or_seq, context=None):
"""Check if a node 'isinstance' any node in class_or_seq
:param node: A given node
:param class_or_seq: Union[nodes.NodeNG, Sequence[nodes.NodeNG]]
| python | {
"resource": ""
} |
q31031 | object_issubclass | train | def object_issubclass(node, class_or_seq, context=None):
"""Check if a type is a subclass of any node in class_or_seq
:param node: A given node
:param class_or_seq: Union[Nodes.NodeNG, Sequence[nodes.NodeNG]]
:rtype: bool
:raises AstroidTypeError: if the given ``classes_or_seq`` are not types
... | python | {
"resource": ""
} |
q31032 | safe_infer | train | def safe_infer(node, context=None):
"""Return the inferred value for the given node.
Return None if inference failed or if there is some ambiguity (more than
one node has been inferred).
"""
try:
inferit = node.infer(context=context)
value = next(inferit)
except exceptions.Infer... | python | {
"resource": ""
} |
q31033 | has_known_bases | train | def has_known_bases(klass, context=None):
"""Return true if all base classes of a class could be inferred."""
try:
return klass._all_bases_known
except AttributeError:
pass
for base in klass.bases:
result = safe_infer(base, context=context)
# TODO: check for A->B->A->B pa... | python | {
"resource": ""
} |
q31034 | class_instance_as_index | train | def class_instance_as_index(node):
"""Get the value as an index for the given instance.
If an instance provides an __index__ method, then it can
be used in some scenarios where an integer is expected,
for instance when multiplying or subscripting a list.
"""
context = contextmod.InferenceContex... | python | {
"resource": ""
} |
q31035 | object_len | train | def object_len(node, context=None):
"""Infer length of given node object
:param Union[nodes.ClassDef, nodes.Instance] node:
:param node: Node to infer length of
:raises AstroidTypeError: If an invalid node is returned
from __len__ method or no __len__ method exists
:raises InferenceError: ... | python | {
"resource": ""
} |
q31036 | _indent | train | def _indent(text, prefix, predicate=None):
"""Adds 'prefix' to the beginning of selected lines in 'text'.
If 'predicate' is provided, 'prefix' will only be added to the lines
where 'predicate(line)' is True. If 'predicate' is not provided,
it will default to adding 'prefix' to all non-empty lines that ... | python | {
"resource": ""
} |
q31037 | _six_fail_hook | train | def _six_fail_hook(modname):
"""Fix six.moves imports due to the dynamic nature of this
class.
Construct a pseudo-module which contains all the necessary imports
for six
:param modname: Name of failed module
:type modname: str
:return: An astroid module
:rtype: nodes.Module
"""
... | python | {
"resource": ""
} |
q31038 | find_spec | train | def find_spec(modpath, path=None):
"""Find a spec for the given module.
:type modpath: list or tuple
:param modpath:
split module's name (i.e name of a module or package split
on '.'), with leading empty strings for explicit relative import
:type path: list or None
:param path:
o... | python | {
"resource": ""
} |
q31039 | Super.super_mro | train | def super_mro(self):
"""Get the MRO which will be used to lookup attributes in this super."""
if not isinstance(self.mro_pointer, scoped_nodes.ClassDef):
raise exceptions.SuperError(
"The first argument to super must be a subtype of "
"type, not {mro_pointer}.... | python | {
"resource": ""
} |
q31040 | Super.igetattr | train | def igetattr(self, name, context=None):
"""Retrieve the inferred values of the given attribute name."""
if name in self.special_attributes:
yield self.special_attributes.lookup(name)
return
try:
mro = self.super_mro()
# Don't let invalid MROs or inva... | python | {
"resource": ""
} |
q31041 | TransformVisitor._transform | train | def _transform(self, node):
"""Call matching transforms for the given node if any and return the
transformed node.
"""
cls = node.__class__
if cls not in self.transforms:
# no transform registered for this class of node
return node
transforms = se... | python | {
"resource": ""
} |
q31042 | TransformVisitor.unregister_transform | train | def unregister_transform(self, node_class, transform, predicate=None):
| python | {
"resource": ""
} |
q31043 | _looks_like_lru_cache | train | def _looks_like_lru_cache(node):
"""Check if the given function node is decorated with lru_cache."""
if not node.decorators:
return False
| python | {
"resource": ""
} |
q31044 | _looks_like_functools_member | train | def _looks_like_functools_member(node, member):
"""Check if the given Call node is a functools.partial call"""
if isinstance(node.func, astroid.Name):
return node.func.name == | python | {
"resource": ""
} |
q31045 | FilterStmtsMixin._get_filtered_stmts | train | def _get_filtered_stmts(self, _, node, _stmts, mystmt):
"""method used in _filter_stmts to get statements and trigger break"""
if self.statement() is mystmt:
| python | {
"resource": ""
} |
q31046 | ImportFromMixin.real_name | train | def real_name(self, asname):
"""get name from 'as' name"""
for name, _asname in self.names:
if name == "*":
return asname
if not _asname:
name = name.split(".", | python | {
"resource": ""
} |
q31047 | parse_function_type_comment | train | def parse_function_type_comment(type_comment: str) -> Optional[FunctionType]:
"""Given a correct type comment, obtain a FunctionType object"""
if _ast_py3 is None:
return None | python | {
"resource": ""
} |
q31048 | is_decorated_with_attrs | train | def is_decorated_with_attrs(node, decorator_names=ATTRS_NAMES):
"""Return True if a decorated node has
an attr decorator applied."""
if not node.decorators:
return False
for decorator_attribute in | python | {
"resource": ""
} |
q31049 | attr_attributes_transform | train | def attr_attributes_transform(node):
"""Given that the ClassNode has an attr decorator,
rewrite class attributes as instance attributes
"""
# Astroid can't infer this attribute properly
# Prevents https://github.com/PyCQA/pylint/issues/1884
node.locals["__attrs_attrs__"] = [astroid.Unknown(paren... | python | {
"resource": ""
} |
q31050 | proxy_alias | train | def proxy_alias(alias_name, node_type):
"""Get a Proxy from the given name to the given node type."""
proxy = type(
alias_name,
| python | {
"resource": ""
} |
q31051 | limit_inference | train | def limit_inference(iterator, size):
"""Limit inference amount.
Limit inference amount to help with performance issues with
exponentially exploding possible results.
:param iterator: Inference generator to limit
:type iterator: Iterator(NodeNG)
:param size: Maximum mount of nodes yielded plus... | python | {
"resource": ""
} |
q31052 | builtin_lookup | train | def builtin_lookup(name):
"""lookup a name into the builtin module
return the list of matching statements and the astroid for the builtin
module
"""
builtin_astroid = MANAGER.ast_from_module(builtins)
if name == "__dict__":
| python | {
"resource": ""
} |
q31053 | _infer_decorator_callchain | train | def _infer_decorator_callchain(node):
"""Detect decorator call chaining and see if the end result is a
static or a classmethod.
"""
if not isinstance(node, FunctionDef):
return None
if not node.parent:
return None
try:
result = next(node.infer_call_result(node.parent))
... | python | {
"resource": ""
} |
q31054 | _rec_get_names | train | def _rec_get_names(args, names=None):
"""return a list of all argument names"""
if names is None:
names = []
| python | {
"resource": ""
} |
q31055 | _is_metaclass | train | def _is_metaclass(klass, seen=None):
""" Return if the given class can be
used as a metaclass.
"""
if klass.name == "type":
return True
if seen is None:
seen = set()
for base in klass.bases:
try:
for baseobj in base.infer():
baseobj_name = base... | python | {
"resource": ""
} |
q31056 | _class_type | train | def _class_type(klass, ancestors=None):
"""return a ClassDef node type to differ metaclass and exception
from 'regular' classes
"""
# XXX we have to store ancestors in case we have an ancestor loop
if klass._type is not None:
return klass._type
if _is_metaclass(klass):
klass._typ... | python | {
"resource": ""
} |
q31057 | get_wrapping_class | train | def get_wrapping_class(node):
"""Get the class that wraps the given node.
We consider that a class wraps a node if the class
is a parent for the said node.
:returns: The class that wraps the given node
:rtype: ClassDef or None
"""
klass = node.frame()
while klass is not None and | python | {
"resource": ""
} |
q31058 | LocalsDictNodeNG.qname | train | def qname(self):
"""Get the 'qualified' name of the node.
For example: module.name, module.class.name ...
:returns: The qualified name.
:rtype: str
"""
# pylint: disable=no-member; github.com/pycqa/astroid/issues/278
| python | {
"resource": ""
} |
q31059 | LocalsDictNodeNG._scope_lookup | train | def _scope_lookup(self, node, name, offset=0):
"""XXX method for interfacing the scope lookup"""
try:
stmts = node._filter_stmts(self.locals[name], self, offset)
except KeyError:
stmts = ()
if stmts:
return self, stmts
if self.parent: # i.e. n... | python | {
"resource": ""
} |
q31060 | LocalsDictNodeNG.set_local | train | def set_local(self, name, stmt):
"""Define that the given name is declared in the given statement node.
.. seealso:: :meth:`scope`
:param name: The name that is being defined.
:type name: str
:param stmt: The statement that defines the given name.
| python | {
"resource": ""
} |
q31061 | LocalsDictNodeNG._append_node | train | def _append_node(self, child):
"""append a child, linking it in the tree"""
# pylint: disable=no-member; depending by the class
| python | {
"resource": ""
} |
q31062 | LocalsDictNodeNG.add_local_node | train | def add_local_node(self, child_node, name=None):
"""Append a child that should alter the locals of this scope node.
:param child_node: The child node that will alter locals.
:type child_node: NodeNG
:param name: The name of | python | {
"resource": ""
} |
q31063 | Module.scope_lookup | train | def scope_lookup(self, node, name, offset=0):
"""Lookup where the given variable is assigned.
:param node: The node to look for assignments up to.
Any assignments after the given node are ignored.
:type node: NodeNG
:param name: The name of the variable to find assignments ... | python | {
"resource": ""
} |
q31064 | Module.import_module | train | def import_module(self, modname, relative_only=False, level=None):
"""Get the ast for a given module as if imported from this module.
:param modname: The name of the module to "import".
:type modname: str
:param relative_only: Whether to only consider relative imports.
:type re... | python | {
"resource": ""
} |
q31065 | Module.relative_to_absolute_name | train | def relative_to_absolute_name(self, modname, level):
"""Get the absolute module name for a relative import.
The relative import can be implicit or explicit.
:param modname: The module name to convert.
:type modname: str
:param level: The level of relative import.
:type... | python | {
"resource": ""
} |
q31066 | Module.wildcard_import_names | train | def wildcard_import_names(self):
"""The list of imported names when this module is 'wildcard imported'.
It doesn't include the '__builtins__' name which is added by the
current CPython implementation of wildcard imports.
:returns: The list of imported names.
:rtype: list(str)
... | python | {
"resource": ""
} |
q31067 | Lambda.type | train | def type(self):
"""Whether this is a method or function.
:returns: 'method' if this is a method, 'function' otherwise.
:rtype: str
| python | {
"resource": ""
} |
q31068 | Lambda.argnames | train | def argnames(self):
"""Get the names of each of the arguments.
:returns: The names of the arguments.
:rtype: list(str)
"""
# pylint: disable=no-member; github.com/pycqa/astroid/issues/291
# args is in fact redefined later on by postinit. Can't be changed
# to Non... | python | {
"resource": ""
} |
q31069 | Lambda.scope_lookup | train | def scope_lookup(self, node, name, offset=0):
"""Lookup where the given names is assigned.
:param node: The node to look for assignments up to.
Any assignments after the given node are ignored.
:type node: NodeNG
:param name: The name to find assignments for.
:type ... | python | {
"resource": ""
} |
q31070 | FunctionDef.extra_decorators | train | def extra_decorators(self):
"""The extra decorators that this function can have.
Additional decorators are considered when they are used as
assignments, as in ``method = staticmethod(method)``.
The property will return all the callables that are used for
decoration.
:ty... | python | {
"resource": ""
} |
q31071 | FunctionDef.type | train | def type(self):
"""The function type for this node.
Possible values are: method, function, staticmethod, classmethod.
:type: str
"""
builtin_descriptors = {"classmethod", "staticmethod"}
for decorator in self.extra_decorators:
if decorator.func.name in buil... | python | {
"resource": ""
} |
q31072 | FunctionDef.getattr | train | def getattr(self, name, context=None):
"""this method doesn't look in the instance_attrs dictionary since it's
done by an Instance proxy at inference time.
"""
if name in self.instance_attrs:
return self.instance_attrs[name]
if | python | {
"resource": ""
} |
q31073 | FunctionDef.igetattr | train | def igetattr(self, name, context=None):
"""Inferred getattr, which returns an iterator of inferred statements."""
try:
return bases._infer_stmts(self.getattr(name, context), context, frame=self)
except exceptions.AttributeInferenceError as error:
| python | {
"resource": ""
} |
q31074 | FunctionDef.decoratornames | train | def decoratornames(self):
"""Get the qualified names of each of the decorators on this function.
:returns: The names of the decorators.
:rtype: set(str)
"""
result = set()
decoratornodes = []
if self.decorators is not None:
decoratornodes += self.deco... | python | {
"resource": ""
} |
q31075 | FunctionDef.is_abstract | train | def is_abstract(self, pass_is_abstract=True):
"""Check if the method is abstract.
A method is considered abstract if any of the following is true:
* The only statement is 'raise NotImplementedError'
* The only statement is 'pass' and pass_is_abstract is True
* The method is anno... | python | {
"resource": ""
} |
q31076 | FunctionDef.infer_call_result | train | def infer_call_result(self, caller=None, context=None):
"""Infer what the function returns when called.
:returns: What the function returns.
:rtype: iterable(NodeNG or Uninferable) or None
"""
if self.is_generator():
if isinstance(self, AsyncFunctionDef):
... | python | {
"resource": ""
} |
q31077 | ClassDef.implicit_locals | train | def implicit_locals(self):
"""Get implicitly defined class definition locals.
:returns: the the name and Const pair for each local
:rtype: tuple(tuple(str, node_classes.Const), ...)
"""
locals_ = (("__module__", self.special_attributes.attr___module__),)
if sys.version_i... | python | {
"resource": ""
} |
q31078 | ClassDef.is_subtype_of | train | def is_subtype_of(self, type_name, context=None):
"""Whether this class is a subtype of the given type.
:param type_name: The name of the type of check against.
:type type_name: str
:returns: True if this class is a subtype of the given type,
False otherwise.
:rtype... | python | {
"resource": ""
} |
q31079 | ClassDef.infer_call_result | train | def infer_call_result(self, caller, context=None):
"""infer what a class is returning when called"""
if (
self.is_subtype_of("%s.type" % (BUILTINS,), context)
and len(caller.args) == 3
):
result = self._infer_type_call(caller, context)
yield result... | python | {
"resource": ""
} |
q31080 | ClassDef.scope_lookup | train | def scope_lookup(self, node, name, offset=0):
"""Lookup where the given name is assigned.
:param node: The node to look for assignments up to.
Any assignments after the given node are ignored.
:type node: NodeNG
:param name: The name to find assignments for.
:type n... | python | {
"resource": ""
} |
q31081 | ClassDef.ancestors | train | def ancestors(self, recurs=True, context=None):
"""Iterate over the base classes in prefixed depth first order.
:param recurs: Whether to recurse or return direct ancestors only.
:type recurs: bool
:returns: The base classes
:rtype: iterable(NodeNG)
"""
# FIXME:... | python | {
"resource": ""
} |
q31082 | ClassDef.local_attr_ancestors | train | def local_attr_ancestors(self, name, context=None):
"""Iterate over the parents that define the given name.
:param name: The name to find definitions for.
:type name: str
:returns: The parents that define the given name.
:rtype: iterable(NodeNG)
"""
# Look up in... | python | {
"resource": ""
} |
q31083 | ClassDef.instance_attr_ancestors | train | def instance_attr_ancestors(self, name, context=None):
"""Iterate over the parents that define the given name as an attribute.
:param name: The name to find definitions for.
:type name: str
:returns: The parents that define the given name as
| python | {
"resource": ""
} |
q31084 | ClassDef.local_attr | train | def local_attr(self, name, context=None):
"""Get the list of assign nodes associated to the given name.
Assignments are looked for in both this class and in parents.
:returns: The list of assignments to the given name.
:rtype: list(NodeNG)
:raises AttributeInferenceError: If n... | python | {
"resource": ""
} |
q31085 | ClassDef.instance_attr | train | def instance_attr(self, name, context=None):
"""Get the list of nodes associated to the given attribute name.
Assignments are looked for in both this class and in parents.
:returns: The list of assignments to the given name.
:rtype: list(NodeNG)
:raises AttributeInferenceError... | python | {
"resource": ""
} |
q31086 | ClassDef.getattr | train | def getattr(self, name, context=None, class_context=True):
"""Get an attribute from this class, using Python's attribute semantic.
This method doesn't look in the :attr:`instance_attrs` dictionary
since it is done by an :class:`Instance` proxy at inference time.
It may return an :class:... | python | {
"resource": ""
} |
q31087 | ClassDef._metaclass_lookup_attribute | train | def _metaclass_lookup_attribute(self, name, context):
"""Search the given name in the implicit and the explicit metaclass."""
attrs = set()
implicit_meta = self.implicit_metaclass()
metaclass = self.metaclass()
for cls in {implicit_meta, metaclass}:
| python | {
"resource": ""
} |
q31088 | ClassDef.igetattr | train | def igetattr(self, name, context=None, class_context=True):
"""Infer the possible values of the given variable.
:param name: The name of the variable to infer.
:type name: str
:returns: The inferred possible values.
:rtype: iterable(NodeNG or Uninferable)
"""
# ... | python | {
"resource": ""
} |
q31089 | ClassDef.getitem | train | def getitem(self, index, context=None):
"""Return the inference of a subscript.
This is basically looking up the method in the metaclass and calling it.
:returns: The inferred value of a subscript to this class.
:rtype: NodeNG
:raises AstroidTypeError: If this class does not d... | python | {
"resource": ""
} |
q31090 | ClassDef.methods | train | def methods(self):
"""Iterate over all of the method defined in this class and its parents.
:returns: The methods defined on the class.
:rtype: iterable(FunctionDef)
"""
done = {}
for astroid in itertools.chain(iter((self,)), self.ancestors()):
| python | {
"resource": ""
} |
q31091 | ClassDef.declared_metaclass | train | def declared_metaclass(self, context=None):
"""Return the explicit declared metaclass for the current class.
An explicit declared metaclass is defined
either by passing the ``metaclass`` keyword argument
in the class definition line (Python 3) or (Python 2) by
having a ``__metac... | python | {
"resource": ""
} |
q31092 | ClassDef._islots | train | def _islots(self):
""" Return an iterator with the inferred slots. """
if "__slots__" not in self.locals:
return None
for slots in self.igetattr("__slots__"):
# check if __slots__ is a valid type
for meth in ITER_METHODS:
try:
... | python | {
"resource": ""
} |
q31093 | ClassDef.slots | train | def slots(self):
"""Get all the slots for this node.
:returns: The names of slots for this class.
If the class doesn't define any slot, through the ``__slots__``
variable, then this function will return a None.
Also, it will return None in the case the slots were not... | python | {
"resource": ""
} |
q31094 | infer_dict | train | def infer_dict(node, context=None):
"""Try to infer a dict call to a Dict node.
The function treats the following cases:
* dict()
* dict(mapping)
* dict(iterable)
* dict(iterable, **kwargs)
* dict(mapping, **kwargs)
* dict(**kwargs)
If a case can't be infer... | python | {
"resource": ""
} |
q31095 | infer_super | train | def infer_super(node, context=None):
"""Understand super calls.
There are some restrictions for what can be understood:
* unbounded super (one argument form) is not understood.
* if the super call is not inside a function (classmethod or method),
then the default inference will be u... | python | {
"resource": ""
} |
q31096 | infer_getattr | train | def infer_getattr(node, context=None):
"""Understand getattr calls
If one of the arguments is an Uninferable object, then the
result will be an Uninferable object. Otherwise, the normal attribute
lookup will be done.
"""
obj, attr = _infer_getattr_args(node, context)
if (
obj is uti... | python | {
"resource": ""
} |
q31097 | infer_hasattr | train | def infer_hasattr(node, context=None):
"""Understand hasattr calls
This always guarantees three possible outcomes for calling
hasattr: Const(False) when we are sure that the object
doesn't have the intended attribute, Const(True) when
we know that the object has the attribute and Uninferable
wh... | python | {
"resource": ""
} |
q31098 | infer_callable | train | def infer_callable(node, context=None):
"""Understand callable calls
This follows Python's semantics, where an object
is callable if it provides an attribute __call__,
even though that attribute is something which can't be
called.
"""
if len(node.args) != 1:
# Invalid callable call.... | python | {
"resource": ""
} |
q31099 | infer_bool | train | def infer_bool(node, context=None):
"""Understand bool calls."""
if len(node.args) > 1:
# Invalid bool call.
raise UseInferenceDefault
if not node.args:
return nodes.Const(False)
argument = node.args[0]
try:
inferred = next(argument.infer(context=context))
excep... | python | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.