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

Function as_int

src/licensedcode/models.py:2248–2259  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

2246
2247
2248def 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)

Callers 5

loadMethod · 0.85
setupMethod · 0.85
to_referenceMethod · 0.85
to_dictMethod · 0.85
loadMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected