Lichen

lib/__builtins__/operator.py

1022:582d834d392d
14 months ago Paul Boddie Merged changes from the value-replacement branch. value-replacement-for-wrapper
     1 #!/usr/bin/env python     2      3 """     4 Operator-related functions.     5      6 Copyright (C) 2015, 2016 Paul Boddie <paul@boddie.org.uk>     7      8 This program is free software; you can redistribute it and/or modify it under     9 the terms of the GNU General Public License as published by the Free Software    10 Foundation; either version 3 of the License, or (at your option) any later    11 version.    12     13 This program is distributed in the hope that it will be useful, but WITHOUT    14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS    15 FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more    16 details.    17     18 You should have received a copy of the GNU General Public License along with    19 this program.  If not, see <http://www.gnu.org/licenses/>.    20 """    21     22 def _binary_op(this, other, op):    23     24     "Test the types of 'this' and 'other', performing 'op' if identical."    25     26     if this.__class__ is other.__class__:    27         return op(this, other)    28     else:    29         return NotImplemented    30     31 def _negate(result):    32     33     "Negate any valid logical value."    34     35     if result is NotImplemented:    36         return result    37     else:    38         return not result    39     40 # vim: tabstop=4 expandtab shiftwidth=4