def const_infer_unary_op(self, operator): if operator == 'not': return node_classes.const_factory(not self.value) # XXX log potentially raised TypeError elif operator == '+': return node_classes.const_factory(+self.value) else: # operator == '-': return node_classes.const_factory(-self.value)
def const_infer_binary_op(self, binop, other, context): operator = binop.op for other in other.infer(context): if isinstance(other, nodes.Const): try: impl = BIN_OP_IMPL[operator] try: yield node_classes.const_factory( impl(self.value, other.value)) except Exception: # ArithmeticError is not enough: float >> float is a TypeError # TODO : let pylint know about the problem pass except TypeError: # XXX log TypeError continue elif other is util.YES: yield other else: try: for val in other.infer_binary_op(binop, self, context): yield val except AttributeError: yield util.YES
def _arguments_infer_argname(self, name, context): # arguments information may be missing, in which case we can't do anything # more if not (self.args or self.vararg or self.kwarg): yield util.YES return # first argument of instance/class method if self.args and getattr(self.args[0], 'name', None) == name: functype = self.parent.type if functype == 'method': yield bases.Instance(self.parent.parent.frame()) return if functype == 'classmethod': yield self.parent.parent.frame() return if context and context.callcontext: call_site = arguments.CallSite(context.callcontext) for value in call_site.infer_argument(self.parent, name, context): yield value return # TODO: just provide the type here, no need to have an empty Dict. if name == self.vararg: vararg = node_classes.const_factory(()) vararg.parent = self yield vararg return if name == self.kwarg: kwarg = node_classes.const_factory({}) kwarg.parent = self yield kwarg return # if there is a default value, yield it. And then yield YES to reflect # we can't guess given argument value try: context = contextmod.copy_context(context) for inferred in self.default_value(name).infer(context): yield inferred yield util.YES except exceptions.NoDefault: yield util.YES
def const_infer_binary_op(self, operator, other, context): for other in other.infer(context): if isinstance(other, nodes.Const): try: impl = BIN_OP_IMPL[operator] try: yield node_classes.const_factory(impl(self.value, other.value)) except Exception: # ArithmeticError is not enough: float >> float is a TypeError # TODO : let pylint know about the problem pass except TypeError: # XXX log TypeError continue elif other is util.YES: yield other else: try: for val in other.infer_binary_op(operator, self, context): yield val except AttributeError: yield util.YES
def __init__(self, elts=None): if elts is None: self.elts = [] else: self.elts = [const_factory(e) for e in elts]
def dict_infer_unary_op(self, operator): if operator == 'not': return node_classes.const_factory(not bool(self.items)) raise TypeError() # XXX log unsupported operation