Convert ``num`` to int if ``num`` is not an int and this would not lead to loss of information, e.g. when ``num`` is an int stored as a float type.
(num)
| 2246 | |
| 2247 | |
| 2248 | def as_int(num): |
| 2249 | """ |
| 2250 | Convert ``num`` to int if ``num`` is not an int and this would not lead to |
| 2251 | loss of information, e.g. when ``num`` is an int stored as a float type. |
| 2252 | """ |
| 2253 | if isinstance(num, str): |
| 2254 | num = float(num) |
| 2255 | if isinstance(num, float): |
| 2256 | n = int(num) |
| 2257 | if n == num: |
| 2258 | return n |
| 2259 | return num |
| 2260 | |
| 2261 | |
| 2262 | @attr.s(slots=True) |
no outgoing calls
no test coverage detected