コード例 #1
0
ファイル: protocols.py プロジェクト: YonghoAhn/JSDN_JSS
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)
コード例 #2
0
ファイル: protocols.py プロジェクト: Andrewou2010/webview
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)
コード例 #3
0
ファイル: protocols.py プロジェクト: Andrewou2010/webview
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
コード例 #4
0
ファイル: protocols.py プロジェクト: Andrewou2010/webview
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
コード例 #5
0
ファイル: protocols.py プロジェクト: YonghoAhn/JSDN_JSS
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
コード例 #6
0
ファイル: protocols.py プロジェクト: esabelhaus/pylintr
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
コード例 #7
0
ファイル: objects.py プロジェクト: shahmatwu/appstrength
 def __init__(self, elts=None):
     if elts is None:
         self.elts = []
     else:
         self.elts = [const_factory(e) for e in elts]
コード例 #8
0
ファイル: protocols.py プロジェクト: Andrewou2010/webview
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
コード例 #9
0
 def __init__(self, elts=None):
     if elts is None:
         self.elts = []
     else:
         self.elts = [const_factory(e) for e in elts]
コード例 #10
0
ファイル: protocols.py プロジェクト: YonghoAhn/JSDN_JSS
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