Python operator.__name__() Examples

The following are 9 code examples of operator.__name__(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module operator , or try the search function .
Example #1
Source File: compiler.py    From stdm with GNU General Public License v2.0 6 votes vote down vote up
def visit_unary(self, unary, **kw):
        if unary.operator:
            if unary.modifier:
                raise exc.CompileError(
                    "Unary expression does not support operator "
                    "and modifier simultaneously")
            disp = getattr(self, "visit_%s_unary_operator" %
                           unary.operator.__name__, None)
            if disp:
                return disp(unary, unary.operator, **kw)
            else:
                return self._generate_generic_unary_operator(
                    unary, OPERATORS[unary.operator], **kw)
        elif unary.modifier:
            disp = getattr(self, "visit_%s_unary_modifier" %
                           unary.modifier.__name__, None)
            if disp:
                return disp(unary, unary.modifier, **kw)
            else:
                return self._generate_generic_unary_modifier(
                    unary, OPERATORS[unary.modifier], **kw)
        else:
            raise exc.CompileError(
                "Unary expression has no operator or modifier") 
Example #2
Source File: compiler.py    From stdm with GNU General Public License v2.0 6 votes vote down vote up
def visit_binary(self, binary, **kw):
        # don't allow "? = ?" to render
        if self.ansi_bind_rules and \
                isinstance(binary.left, elements.BindParameter) and \
                isinstance(binary.right, elements.BindParameter):
            kw['literal_binds'] = True

        operator = binary.operator
        disp = getattr(self, "visit_%s_binary" % operator.__name__, None)
        if disp:
            return disp(binary, operator, **kw)
        else:
            try:
                opstring = OPERATORS[operator]
            except KeyError:
                raise exc.UnsupportedCompilationError(self, operator)
            else:
                return self._generate_generic_binary(binary, opstring, **kw) 
Example #3
Source File: compiler.py    From moviegrabber with GNU General Public License v3.0 6 votes vote down vote up
def visit_unary(self, unary, **kw):
        if unary.operator:
            if unary.modifier:
                raise exc.CompileError(
                        "Unary expression does not support operator "
                        "and modifier simultaneously")
            disp = getattr(self, "visit_%s_unary_operator" %
                                    unary.operator.__name__, None)
            if disp:
                return disp(unary, unary.operator, **kw)
            else:
                return self._generate_generic_unary_operator(unary,
                                    OPERATORS[unary.operator], **kw)
        elif unary.modifier:
            disp = getattr(self, "visit_%s_unary_modifier" %
                                    unary.modifier.__name__, None)
            if disp:
                return disp(unary, unary.modifier, **kw)
            else:
                return self._generate_generic_unary_modifier(unary,
                                    OPERATORS[unary.modifier], **kw)
        else:
            raise exc.CompileError(
                            "Unary expression has no operator or modifier") 
Example #4
Source File: compiler.py    From moviegrabber with GNU General Public License v3.0 6 votes vote down vote up
def visit_binary(self, binary, **kw):
        # don't allow "? = ?" to render
        if self.ansi_bind_rules and \
            isinstance(binary.left, elements.BindParameter) and \
            isinstance(binary.right, elements.BindParameter):
            kw['literal_binds'] = True

        operator = binary.operator
        disp = getattr(self, "visit_%s_binary" % operator.__name__, None)
        if disp:
            return disp(binary, operator, **kw)
        else:
            try:
                opstring = OPERATORS[operator]
            except KeyError:
                raise exc.UnsupportedCompilationError(self, operator)
            else:
                return self._generate_generic_binary(binary, opstring, **kw) 
Example #5
Source File: elements.py    From sqlalchemy with MIT License 5 votes vote down vote up
def __repr__(self):
        friendly = self.description
        if friendly is None:
            return object.__repr__(self)
        else:
            return "<%s.%s at 0x%x; %s>" % (
                self.__module__,
                self.__class__.__name__,
                id(self),
                friendly,
            ) 
Example #6
Source File: elements.py    From sqlalchemy with MIT License 5 votes vote down vote up
def __getattr__(self, key):
        try:
            return getattr(self.comparator, key)
        except AttributeError as err:
            util.raise_(
                AttributeError(
                    "Neither %r object nor %r object has an attribute %r"
                    % (
                        type(self).__name__,
                        type(self.comparator).__name__,
                        key,
                    )
                ),
                replace_context=err,
            ) 
Example #7
Source File: elements.py    From sqlalchemy with MIT License 5 votes vote down vote up
def _construct(cls, operator, continue_on, skip_on, *clauses, **kw):
        lcc, convert_clauses = cls._process_clauses_for_boolean(
            operator,
            continue_on,
            skip_on,
            [
                coercions.expect(roles.WhereHavingRole, clause)
                for clause in util.coerce_generator_arg(clauses)
            ],
        )

        if lcc > 1:
            # multiple elements.  Return regular BooleanClauseList
            # which will link elements against the operator.
            return cls._construct_raw(operator, convert_clauses)
        elif lcc == 1:
            # just one element.  return it as a single boolean element,
            # not a list and discard the operator.
            return convert_clauses[0]
        else:
            # no elements period.  deprecated use case.  return an empty
            # ClauseList construct that generates nothing unless it has
            # elements added to it.
            util.warn_deprecated(
                "Invoking %(name)s() without arguments is deprecated, and "
                "will be disallowed in a future release.   For an empty "
                "%(name)s() construct, use %(name)s(%(continue_on)s, *args)."
                % {
                    "name": operator.__name__,
                    "continue_on": "True"
                    if continue_on is True_._singleton
                    else "False",
                },
                version="1.4",
            )
            return cls._construct_raw(operator) 
Example #8
Source File: TLorentzVector.py    From uproot-methods with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _scalar(self, operator, scalar, reverse=False):
        cart = self._to_cartesian()
        if not isinstance(scalar, (numbers.Number, self.awkward.numpy.number)):
            raise TypeError("cannot {0} a TLorentzVector with a {1}".format(operator.__name__, type(scalar).__name__))
        if reverse:
            return TLorentzVector(operator(scalar, cart.x), operator(scalar, cart.y), operator(scalar, cart.z), operator(scalar, cart.t))
        else:
            return TLorentzVector(operator(cart.x, scalar), operator(cart.y, scalar), operator(cart.z, scalar), operator(cart.t, scalar)) 
Example #9
Source File: TLorentzVector.py    From uproot-methods with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _vector(self, operator, vector, reverse=False):
        cart = self._to_cartesian()
        if not isinstance(vector, Methods):
            raise TypeError("cannot {0} a TLorentzVector with a {1}".format(operator.__name__, type(vector).__name__))
        if reverse:
            return TLorentzVector(operator(vector.x, cart.x), operator(vector.y, cart.y), operator(vector.z, cart.z), operator(vector.t, cart.t))
        else:
            return TLorentzVector(operator(cart.x, vector.x), operator(cart.y, vector.y), operator(cart.z, vector.z), operator(cart.t, vector.t))