MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / _make_operator

Function _make_operator

src/licensedcode/_vendor/attr/_cmp.py:117–137  ·  view source on GitHub ↗

Create operator method.

(name, func)

Source from the content-addressed store, hash-verified

115
116
117def _make_operator(name, func):
118 """
119 Create operator method.
120 """
121
122 def method(self, other):
123 if not self._is_comparable_to(other):
124 return NotImplemented
125
126 result = func(self.value, other.value)
127 if result is NotImplemented:
128 return NotImplemented
129
130 return result
131
132 method.__name__ = "__%s__" % (name,)
133 method.__doc__ = "Return a %s b. Computed by attrs." % (
134 _operation_names[name],
135 )
136
137 return method
138
139
140def _is_comparable_to(self, other):

Callers 1

cmp_usingFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected