MCPcopy Create free account
hub / github.com/argotorg/solidity / _humanize_diff

Method _humanize_diff

scripts/externalTests/benchmark_diff.py:136–177  ·  view source on GitHub ↗
(self, diff: Union[str, int, float])

Source from the content-addressed store, hash-verified

134 return diff
135
136 def _humanize_diff(self, diff: Union[str, int, float]) -> str:
137 def wrap(value: str, symbol: str):
138 return f"{symbol}{value}{symbol}"
139
140 markdown = (self.output_format == OutputFormat.MARKDOWN)
141
142 if isinstance(diff, str) and diff.startswith('!'):
143 return wrap(diff, '`' if markdown else '')
144
145 value: Union[str, int, float]
146 if isinstance(diff, (int, float)):
147 value = diff * 100
148 if isinstance(value, float) and self.relative_precision is not None:
149 # The multiplication can result in new significant digits appearing. We need to reround.
150 # NOTE: round() works fine with negative precision.
151 value = round(value, self.relative_precision - 2)
152 if isinstance(value, float) and value.is_integer():
153 value = int(value)
154 suffix = ''
155 prefix = ''
156 if diff < 0:
157 prefix = ''
158 if markdown:
159 suffix += ' ✅'
160 elif diff > 0:
161 prefix = '+'
162 if markdown:
163 suffix += ' ❌'
164 important = (diff != 0)
165 else:
166 value = diff
167 important = False
168 prefix = ''
169 suffix = ''
170
171 return wrap(
172 wrap(
173 f"{prefix}{value}%{suffix}",
174 '`' if markdown else ''
175 ),
176 '**' if important and markdown else ''
177 )
178
179
180@dataclass(frozen=True)

Callers 2

runMethod · 0.95
_diff_scalarsMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected