(self, diff: Union[str, int, float])
| 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) |
no outgoing calls
no test coverage detected